Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keyboard Shortcuts for HTML buttons...

Status
Not open for further replies.

MattWoberts

Programmer
Oct 12, 2001
156
GB
Hi,

Does anyone know if it possible to add keyboard shortcuts for buttons in a HTML web form. I have a button "Add", and I want the "standard" shortcut technique that underlines the A on the page and allows the user to hit Alt-A instead of having to click the button...

Is there a simple way to do this or I need to add JScript code to trap the keyboard input and look for alt-a?

Thanks!
 
You can use the accesskey attribute to assign a shortcut key to the button.

[tt]<input type=&quot;button&quot; accesskey=&quot;A&quot; value=&quot;Add&quot;>[/tt]

Pressing ALT+A will set the focus to this button.

 
Thats excellent - thanks!

Is there a way to underline the A on the page? Or do I need to use images for the button rather than text....
 
you could:

CSS:

span.accesskey {text-decoration:underline}

XHTML:

<button type=&quot;submit&quot; accesskey=&quot;e&quot;>
<span class=&quot;accesskey&quot;>E</span>nter
</button>
 
Thanks for the help everyone. I couldn't get that link above to work I'm afraid...

The XHTML solution is great, but is it possible to do soemthing similar with plain old HTML using the standard <INPUT type=&quot;button&quot;>?

Thanks

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top