209Chapter 15 .Generic HTML Element Objects function (invoked (Web hosting contract)

209Chapter 15 .Generic HTML Element Objects function (invoked by an onKeyPress event handler) makes sure text entered into a text field is all uppercase, even if you type it as lowercase: function assureUpper() { if (event.charCode >= 97 && event.charCode <= 122) { event.charCode = event.charCode - 32 } } Doing this might confuse (or frustrate) users, so think carefully before implementing such a plan. To prevent a keyboard key press from becoming a typed character in a text field, the onKeyPressevent handler prevents the default action of the event. For example, the following (NN4+, IE4+) HTML page shows how to inspect a text field s entry for numbers only: Keyboard Capture

Enter any positive integer:
Whenever a user enters a non-number, the user receives a warning and the character is not appended to the text box s text. Keyboard events also enable you to script the submission of a form when a user presses the Enter (Return on the Mac) key within a text box. The ASCII value of the Enter/Return key is 13. Therefore, you can examine each key press in a text box and submit the form whenever value 13 arrives, as shown in the following function, which works in IE4+ and NN4+: function checkForEnter(evt) { evt = (evt) ? evt : event var charCode = (evt.which) ? evt.which : evt.keyCode if (charCode == 13) { document.forms[0].submit() return false } return true } elementObject.onKeyDown
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

Leave a Reply