WebAIM - Web Accessibility In Mind

E-mail List Archives

Thread: onclick and onkeypress

for

Number of posts in this thread: 4 (In chronological order)

From: Jared Smith
Date: Thu, Nov 06 2003 12:37PM
Subject: onclick and onkeypress
No previous message | Next message →

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/


From: Andrew Kirkpatrick
Date: Thu, Nov 06 2003 1:17PM
Subject: Re: onclick and onkeypress
← Previous message | Next message →

Jared,
Two machines - one made the second alter appear, one didn't.

OSX IE 5.2 (4609) didn't work onclick
OSX IE 5.2.2 (5010.1) did

This is most significantly an issue when the javascript functionality is
something other than opening a new web page. I usually use the page url in
the href attribute as the fallback for that scenario:

<a href="foo.html" onclick="dothis();return false;">

If the user of the page is using a screen reader, the href="#" can be
disorienting -- instead of a link being followed, nothing happens (this is
pretty common on navigation bars with submenus)

On newer browsers you can apply onclick events to elements other than anchor
tags, which helps solve this problem (but causes additional compatibility
issues, of course)

AWK



On 11/6/03 2:34 PM, "Jared Smith" < = EMAIL ADDRESS REMOVED = > wrote:

> 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/
>

--
Andrew Kirkpatrick
CPB/WGBH National Center for Accessible Media
125 Western Ave.
Boston, MA 02134
E-mail: = EMAIL ADDRESS REMOVED =
Web site: ncam.wgbh.org

617-300-4420 (direct voice/FAX)
617-300-3400 (main NCAM)
617-300-2489 (TTY)

WGBH enriches people's lives through programs and services that educate,
inspire, and entertain, fostering citizenship and culture, the joy of
learning, and the power of diverse perspectives.



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


From: Jukka K. Korpela
Date: Thu, Nov 06 2003 1:32PM
Subject: Re: onclick and onkeypress
← Previous message | Next message →

On Thu, 6 Nov 2003, Jared Smith wrote:

> 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 -

That's problematic indeed.

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

That construct introduces a new problem: when JavaScript is disabled, the
construct becomes a link to the start of the page. Is that feasible?

> However, onkeypress is triggered by pressing ANY alphanumeric key.

By the (vague) definition in the HTML spec, by pressing "a 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.

Your conclusion seems to be right.

> 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).

That's probably the way to go: to make user agents handle onclick
reasonably, in a not-so-device-dependent way.

> 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?

By using (JavaScript) code that tries to detect which key was pressed.
But this gets rather complicated and won't work across all JavaScript
implementations.

--
Jukka "Yucca" Korpela, http://www.cs.tut.fi/~jkorpela/


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


From: Theresa Hansen
Date: Wed, Dec 03 2003 5:47PM
Subject: Accessible message board
← Previous message | No next message

I have a project that needs an easy way for participants in a pilot
project to communicate. The project manager prefers a message board
format that allows for threaded discussions but the solution also needs
to be as accessible as possible. An e-mail list that also provides good
quality threaded archives would probably work. Do you have any
suggestions for products to do this job in the most accessible way?

Thanks for any help you can offer.

Theresa Hansen
University of Alaska Anchorage Center for Human Development



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