Language References
Assigns a shortcut key to set focus or activate an element.
Inline |
<element accessKey = chrKey...> |
Script |
object.accessKey = chrKey |
chrKey |
Single character that denotes an alphanumeric shortcut key. |
The property is read/write with no default value.
The accessKey attribute assigns a single character access key to an element. Pressing the ALT key plus the access key assigned to an element sets the focus to that element.
The action that occurs when an element receives focus depends on the element.
For instance, when a user activates a link defined by the A element, the browser generally follows the link. When a user activates a radio button, the browser changes the value of the radio button. When the user activates a text field, it allows input, and so on.
In addition, some controls perform an action after receiving focus. For example, using accessKey on a button fires the onclick event, whereas using accessKey on a radio button fires the onclick event and toggles the checked property, visibly selecting or deselecting the control.
Authors should consider the input method of the expected user when specifying an accesskey, as the invocation of access keys depends on the underlying system. For instance, on machines running MS Windows®, one generally has to press the ALT key in addition to the access key. On Macintosh® systems, one generally has to press the CMD key in addition to the access key.
The rendering of access keys depends on the browser. It is recommended that authors include the access key in label text or wherever the access key is to apply. Browsers should render the value of an access key in such a way as to emphasize its role and to distinguish it from other characters, like by underlining it.
The following example assigns access keys to LABEL elements associated with INPUT controls on a FORM.
Typing the access key gives focus to the label which in turn gives it to the associated control. The rich text support in the LABEL object makes it possible to underline the designated accessKey.
<table bgcolor="#336699" cellpadding=5>
<col align=right>
<tr>
<td><label for="tb1" accessKey="f">
<u>F</u>irst name </label></td>
<td><input type="Text" value="first name here"
size="20" tabindex="1" id="tb1"></td></tr>
<tr>
<td><label for="tb2" accessKey="l">
<u>L</u>ast name </label></td>
<td><input type="Text" value="last name here"
size="20" tabindex="2" id="tb2"></td></tr>
<tr>
<td><label for="tb3" accessKey="e">
<u>e</u>mail address </label></td>
<td><input type="Text" value="email address here"
size="20" tabindex="3" id="tb3"></td></tr>
<tr>
<td><input type="Radio" name=order id="rb1">
<label for="rb1" accessKey="a">
<u>A</u>dd to order</label></td>
<td><input type="Radio" name=order id="rb2">
<label for="rb2" accessKey="r">
<u>R</u>emove from order</label></td></tr>
</table>
Show me
A, APPLET, AREA, BDO, BUTTON, EMBED, FIELDSET, HTMLAREA, IFRAME, IMG, INPUT, LABEL, LEGEND, OBJECT, SELECT, TABLE, TEXTAREA