The accessKey PropertyThe accessKey property enables you to specify a keyboard character that you can press with the Alt key to give an HTML element the focus (that is, make it the element that will receive keystrokes). You can see the support for this property in Table 5.4. Table 5.4. The accessKey Property
Here's an example that gives a button the access key "b" and a text field the access key "t" : (Listing 05-01.html on the web site)<HTML> <HEAD> <TITLE>Using Access Keys</TITLE> </HEAD> <BODY> <H1>Using Access Keys</H1> <FORM> <INPUT TYPE="BUTTON" ID="button1" ONCLICK="alert('Hello!')" VALUE="Click Me!"> <INPUT TYPE="TEXT" ID="text1" VALUE="Click Me!"> </FORM> <SCRIPT LANGUAGE="JavaScript"> <!-- document.all.button1.accessKey = "b" document.all.text1.accessKey = "t" // --> </SCRIPT> </BODY> </HTML> When you open this page in the Internet Explorer, you can give the focus to the button or text field simply by using Alt + the access key. (Note that giving the button the focus clicks the button.) |