Example for Checkpoint
9.3, continued.

Example
Slide 72 of 120
Previous slide. Next slide.

Example 2: Use more than one device-dependent event handler to "cover all the bases": ONCLICK requires a mouse event, while ONKEYPRESS requires a keyboard event. Both are device dependent, but including both should allow anyone to benefit from the technique.

Another "script-activated button": click on it, or tab to it and press any key to activate the script. A small alert box should pop up containing a message about the prize. Pressing the Escape key will make it go away.

Here is the code that creates the button:

You will win a small prize if you
<BUTTON ONCLICK="pop2()" ONKEYPRESS="pop2()">
Win a different prize!</BUTTON>.

And here is the code for the script function:

<SCRIPT language="JavaScript" type="text/javascript">
function pop2() { alert ("Second Prize!") }
</SCRIPT>
<NOSCRIPT>Second Prize!</NOSCRIPT>

Finally, do not write event handlers that rely on mouse coordinates since this prevents device-independent input.


Up one level To Checkpoints for Guideline 9.
Next slide: Example for Checkpoint 9.4

Introduction: Overview Guidelines: Overview Checkpoints: Overview Examples: Overview

Previous page. Next page.

Chuck Letourneau & Geoff Freed

W3C Web Accessibility Initiative

Copyright © 2000 W3C