346Part IIIDocument Objects Reference} (Cedant web hosting) return true; } By
346Part IIIDocument Objects Reference} return true; } By assigning the checkForEnter()function to each field s onkeypressevent handler, yousuddenly add some extra power to a typical HTML form. You can intercept Ctrl+keyboard combinations (letters only) in HTML pages most effectivelyin Internet Explorer, but only if the browser itself does not use the combination. In otherwords, you cannot redirect Ctrl+key combinations that the browser uses for its own control. The onkeypresskeyCodevalue for Ctrl+combinations ranges from 1 through 26 for letters Athrough Z (except for those used by the browser, in which case no keyboard event fires). ExampleListing 15-41 is a working laboratory that you can use to better understand the way keyboardevent codes and modifier keys work in IE5+ and W3C browsers. The actual code of the listingis less important than watching the page while you use it. For every key or key combinationthat you press, the page shows the keyCodevalue for the onkeydown, onkeypress, andonkeyupevents. If you hold down one or more modifier keys while performing the key press, the modifier key name is highlighted for each of the three events. Note that when run inNN6+, the keyCodevalue is not the character code (which doesn t show up in this examplefor NN6+). Also, you may need to click the NN6+ page for the documentobject to recognizethe keyboard events. The best way to watch what goes on during keyboard events is to press and hold a key to seethe key codes for the onkeydownand onkeypressevents. Then release the key to see the codefor the onkeyupevent. Notice, for instance, that if you press the A key without any modifier key, the onkeydownevent key code is 65 (A) but the onkeypresskey code in IE (and the charCodeproperty in NN6+) is 97 (a). If you then repeat the exercise but hold the Shift key down, all threeevents generate the 65 (A) key code (and the Shift modifier labels are highlighted). Releasingthe Shift key causes the onkeyupevent to show the key code for the Shift key. In another experiment, press any of the four arrow keys. No key code is passed for theonkeypressevent because those keys don t generate those events. They do, however, gener- ate onkeydownand onkeyupevents. Listing 15-41: Keyboard Event Handler Laboratory