Cheap web hosting - 208 Part III .Document Objects Reference Day: Year:

208 Part III .Document Objects Reference Day: Year: These three events do not fire for all keys of the typical PC keyboard on all browser versions that support keyboard events. The only keys that you can rely on supporting the events in all browsers shown in the preceding compatibility chart are the alphanumeric keys represented by ASCII values. This includes keys such as the spacebar and Enter (Return on the Mac), but it excludes all function keys, arrow keys, and other navigation keys. Modifier keys, such as Shift, Ctrl (PC), Alt (PC), Command (Mac), and Option (Mac), generate some events on their own (depending on browser and version). However, functions invoked by other key events can always inspect the pressed states of these modifier keys. Scripting keyboard events almost always entails examining which key is pressed so that some processing or validation can be performed on that key press. This is where the situation gets very complex if you are writing for cross-browser implementation. In some cases, even writing just for Internet Explorer gets tricky because non-alphanumeric keys generate only the onKeyDown and onKeyUpevents. In fact, to fully comprehend keyboard events, you need to make a distinction between key codes and character codes. Every PC keyboard key has a key code associated with it. This key code is always the same regardless of what other keys you press at the same time. Only the alphanumeric keys (letters, numbers, spacebar, and so on), however, generate character codes. The code represents the typed character produced by that key. The value might change if you press a modifier key. For example, if you type the A key by itself, it generates a lowercase a character (character code 97); if you also hold down the Shift key, that same key produces an uppercase A character (character code 65). The key code for that key (65 for Western language keyboards) remains the same no matter what. That brings us, then, to where these different codes are made available to scripts. In all cases, the code information is conveyed as one or two properties of the browser s event object. IE s event object has only one such property keyCode. It contains key codes for onKeyDown and onKeyUpevents, but character codes for onKeyPressevents. The NN6 event object, on the other hand, contains two separate properties: charCode and keyCode. You can find more details and examples about these event object properties in Chapter 29. The bottom-line script consideration is to use either onKeyDownor onKeyUpevent handlers when you want to look for non-alphanumeric key events (for example, function keys, arrow and page navigation keys, and so on). To process characters as they appear in text boxes, use the onKeyPressevent handler. You can experiment with these events and codes in Listing 15-41 as well as in examples from Chapter 29. Common keyboard event tasks IE4+ (but not NN) enables you to modify the character that a user who is editing a text box enters. The onKeyPressevent handler can modify the event.keyCode property and allow the event to continue (in other words, don t evaluate to return false or set the event.returnValue property to false). The following IE elementObject.onKeyDown
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Leave a Reply