| Mouse event | Equivalent keyboard event | 
|---|---|
| onmouseover | onfocus(1) | 
| onmouseout | onblur(1) | 
| onmousedown | onkeydown(2) | 
| onmouseup | onkeyup(2) | 
| onclick | onkeypress(3) | 
Never use the onchange event for automatic form submissions!
Only use onchange rarely and don’t alert users of format errors until time for submission. For example, you may want to use it for slight formatting changes of input data. If a user has typed in (555)555-1212 for a phone number format instead of the requested format, you could change it to 555-555-1212 safely without alerting the user. However, since this type of data manipulation could easily be done at the time of submission or on the server-side, it may still be a good idea not to use onchange.
Keyboard events
- onfocusand- onblur- The - onmouseoverand- onmouseoutevents are most commonly used with image rollovers. While adding the- onfocusand- onblurevents for rollovers is not necessary for screen reader accessibility, it can add usability benefits for sighted users accessing your site with a keyboard. For example, although a mobility-impaired user may not need to see a rollover, he could still benefit from the visual feedback of the effect.- You may also wish to consider using CSS for rollover effects. The CSS image replacement techniques are not fully accessible (and probably won’t be until CSS3 generated content is widely supported), but for text effects it is more than adequate. - a:link { /* normal state */ }
 a:visited { /* visited state */ }
 a:hover, a:active, a:focus { /* rollover state */ }
 - The - :activeand- :focuspsuedo-classes mimic the- :hoverstate for keyboard events. Ideally,- :activewould mimic an- onmousedownor- onkeydownevent, but Internet Explorer incorrectly treats this as- :focusso we double-up the psuedo-classes to get a consistent effect across multiple browsers.- See an example of CSS rollovers versus JavaScript rollovers. - Because newer browsers (like Mozilla) can implement - :hoveron arbitrary elements (not just links), you may want to double-up your pseudo-classes. Combining- :hoverwith- :linkand- :visitedcan ensure the special effects won’t appear on non-link anchors.- a:link { /* normal state */ }
 a:visited { /* visited state */ }
 a:link:hover, a:visited:hover, a:active, a:focus { /* rollover state */ }
 
- onkeydownand- onkeyup- In a few DHTML cases, these events may need to be used instead of - onkeypress. For example, the arrow keys do not consistently activate the the- onkeypressevent, but they usually do activate the- onkeydownand- onkeyupevents.- However knowing that many users do not have arrow keys (laptops for example), consider rethinking your need for these keys if the functionality provides a essential information. Also consider how difficult it may be to use this type of interface with a screen reader. 
- onkeypress- Most browsers activate the - onclickevent when a user presses the Enter key, however certain browsers do not. To ensure full support, you may wish to use the- onkeypressevent.- You could use this example HTML code: - <input
 type="button"
 onclick="foo();"
 onkeypress="verifyKey(this,event);"
 />- With this JavaScript function: - // With onkeypress event, this verifies “Enter” key
 function verifyKey(oElement,oEvent){
 if(oEvent.keyCode==13 && oElement.onclick){
 oElement.onclick();
 }
 }- Note: The verify key function is usually not necessary, but it was written to account for an bug in some older versions of Mozilla. The bug has been fixed in the latest releases, but it previously activated the - onkeypressevent when a user hit the Tab key, making it impossible to tab past the link without activating the event.