11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Keyboard Masking<br />

We‘ve seen how to catch errors at submission time and right after they occur, but what about<br />

preventing them in the first place? <strong>JavaScript</strong> makes it possible to limit the type of data that is<br />

entered into a field as it is typed. This technique catches and prevents errors as they happen.<br />

<strong>The</strong> following script could be used in browsers that support a modern event model (as<br />

discussed in Chapter 11). It forces the field to accept only numeric characters by checking each<br />

character as it is entered in an onkeypress handler:<br />

<br />

<br />

<br />

Numbers-Only Field Mask Demo<br />

<br />

<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!