WebAIM - Web Accessibility In Mind

E-mail List Archives

onclick and onkeypress

for

From: Jared Smith
Date: Nov 6, 2003 12:37PM


I have a problem. When using Javascript, you are not to use mouse
dependent event handlers. Most recommendations are to use both onclick
and onkeypress to accomodate both the mouse and keyboard -
http://www.w3.org/TR/WCAG10-HTML-TECHS/#directly-accessible-scripts

In other words, something like
<a href="#" onclick="dothis()" onkeypress="dothis()">

However, onkeypress is triggered by pressing ANY alphanumeric key.
This means that when users are navigating through the page, the event is
triggered when they press Tab (or 'a' in Opera) while on the link,
thus triggering the javascript all the time, not just when the Enter
key is pressed. This makes the page LESS accessible. This would be
very problematic if the user wants to perform some keyboard action
(i.e., CTL+P to print) while the link has focus.

Most browsers and screen readers seem to interpret the pressing of the
Enter key while focused on a link to be the same as onclick (IE on a
Mac does not).

So, it appears that onkeypress isn't necessary. And if it is, then how
do you limit the onkeypress event to only the Enter key? But if we
remove onkeypress, does anybody have a workaround for IE on a Mac,
which doesn't trigger onclick with the keyboard?

I created at test page at http://acropolis.usu.edu/test.htm to
demonstrate how onkeypress is problematic in Opera and Netscape and
how onclick does not suffice for IE on a Mac.

Jared Smith
WebAIM (Web Accessibility In Mind)
Center for Persons with Disabilities
Utah State University


----
To subscribe, unsubscribe, suspend, or view list archives,
visit http://www.webaim.org/discussion/