Using keyboard keys to activate buttons

Giganews Newsgroups
Subject: Using keyboard keys to activate buttons
Posted by:  MikeB (MPBre…@gmail.com)
Date: Tue, 6 May 2008

Short question:
Can I create a form where the user can simply hit the "1" key on the
keyboard and a button click for a specific button on the form is
simulated?

Long explanation:
Hi, I'm learning HTML and CSS  and JavaScript and all this interesting
stuff.

As an exercise we had a form that had two input fields and one could
press a button and the contents of the two fields would be added
together.

I thought it would be interesting to write an entire calcualtor
(similar to the one that comes with Windows) as an HTML page.

I got most of it right, I have buttons and an input field and buttons
to do the calculations.

What I was hoping to do as the cherry on top was to enable it for
keyboard access, so a user could press the keys (1, 2, 3 etc.) to
enter the values and then the calcualtion key (+, -, *, etc) without
having to click on each button.

I found that I could specify access keys in the HTML, but that works
weird.

In Firefox, it doesn't seem to work at all.

In IE, if I press Alt+1, it will cycle through (and enter) either 1,
2, or 3 (the three buttons I've defined accesskey values for).

Thanks for reading

Replies