Producing web pages
* HTML CSS DHTML XHTML A to Z of tags        Accessibility          Design

6.4 Ensure that event handlers are input device-independent

An event handler is a script that the browser calls when a certain event occurs (e.g. the mouse moves, a key is pressed, the pageis loaded). Some event handlers produce effects which are purely visual but others complete critical tasks such as submitting the contents of a form, completing a calculation or sending a message.

Make sure that event handlers critical to completing a user task are device independent — users must be able to interact with the page using the devices suiting their needs (e.g. a mouse, keyboard, microphone, Braille devices, head wands or other pointing devices).

Use event handlers that work for both mouse users and keyboard users. The event handlers are onfocus, onblur (the opposite of onfocus), and onselect. Note: These attributes are designed to be device-independent, but are implemented as keyboard specific events in current browsers. Otherwise, if you must use device-dependent attributes, provide redundant input mechanisms (i.e., specify two handlers for the same element):

  • Use onmousedown with onkeydown
  • Use onmouseup with onkeyup
  • Use onclick with onkeypress

Note that there is no keyboard equivalent to double-click (ondblclick).

Don't write event handlers that rely on mouse co-ordinates. This is bad practice because it relies on the use of a mouse and a highly visual style of interaction to invoke an event handler. Event handlers that rely on mouse coordinates don't support keyboard input.

To test that event handlers are input device independent, unplug the mouse and navigate the page simply with the keyboard.