By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,648 Members | 1,670 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,648 IT Pros & Developers. It's quick & easy.

Map button on form to key on keyboard

P: n/a
I have a simple form that I'm using to learn something about HTML and
JavaScript.

Can I associate a button on the form with a keyboard key so that when
the user presses the keyboard key the form thinks the button has been
clicked?

Background:
I'm learning HTML and JavaScript. We did a simple JavaScript that had
a button that would add the numbers in two input fields.

I then thought it would be nice to change the form (and the
JavaScript) to make a "real" calculator.http://fmechess.org/demo/
calculator.html

What I would like to do is to make the calculator sensitive to normal
presses of the keyboard keys, so that instead of clicking on the
buttons to enter a calcualtion, the user can simply type on the
keyboard. Is this possible?

Thanks.

PS. I hope this is the right ng to ask in, I got "booted" out of the
HTML ng for asking in there. :)
Jun 27 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
MikeB wrote on 10 mei 2008 in comp.lang.javascript:
I have a simple form that I'm using to learn something about HTML and
JavaScript.

Can I associate a button on the form with a keyboard key so that when
the user presses the keyboard key the form thinks the button has been
clicked?
Yes you can, but not cross browser compatible.
Background:
I'm learning HTML and JavaScript.
Do HTML first, Javascript is another piece of cake.
We did a simple JavaScript that had
a button that would add the numbers in two input fields.
Who is "we", is this a school assignment?
I then thought it would be nice to change the form (and the
JavaScript) to make a "real" calculator.http://fmechess.org/demo/
calculator.html
Better come with som code that jou are imagining.
What I would like to do is to make the calculator sensitive to normal
presses of the keyboard keys, so that instead of clicking on the
buttons to enter a calcualtion, the user can simply type on the
keyboard. Is this possible?
Yes, see above.
Thanks.

PS. I hope this is the right ng to ask in, I got "booted" out of the
HTML ng for asking in there. :)
Are you sure it was not because you are not showing you did do any
reseach yourself before you asked?

Look for HTML 'accesskey' on Google.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #2

P: n/a
In article of Sat, 10 May 2008, MikeB writes
>In Firefox, it doesn't seem to work at all.
ALT + SHIFT + key works in Firefox

Anyone found a combination that works in Opera ?

I have searched their help files to no avail
--
Mervyn Carter
================================================
Note: Spam block in use
To reply direct you only need one "q" in my eddress
================================================
Jun 27 '08 #3

P: n/a
MikeB wrote on 10 mei 2008 in comp.lang.javascript:
You may notice that in that I have mentioned that I have found and
tried using accesskey and that the results were erratic and
unpredictable.
I seem to remember that IE only allows Alt- a to z,
while IE-mobile [also?] allows Alt- 0 to 9.

The results however are not erratic and unpredictable,
they are according to specs of the individual browser.

The same would apply for FF, Opera, Safari, I suppose.
Reading the specs before calling something unpredictable.

The word "Erratic" I would preserve for inconsistent behavour even after
thorough testing of your programme on each targeted browser. Building for
cross browser compatibility is a teduous task.

Errare humanum, debuggere divinum.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #4

P: n/a
On Sun, 11 May 2008 10:06:30 +0000, Evertjan. wrote:
MikeB wrote on 10 mei 2008 in comp.lang.javascript:
>You may notice that in that I have mentioned that I have found and
tried using accesskey and that the results were erratic and
unpredictable.

[...]
The word "Erratic" I would preserve for inconsistent behavour even after
thorough testing of your programme on each targeted browser. Building for
cross browser compatibility is a teduous task.
Unfortunately it's not "just" a (cross-)browser issue. There's something
else involved: the respective GUI. I stumbled over this problem some years
ago when some users where quite happy with the pages' access keys while
others complained that those access keys were misleading and wouldn't
work. I was able able to find two users with the very same browser, the
same OS and even the same GUI. However, what was working on one computer
didn't at the other's. After experimenting and changing the access keys
we finally figured out what the problem was: The GUI-setup allowed for
defining hotkeys for whatever purpose (like invoking programs or
switching desktops). And if such a GUI-based hotkey happens to be the
same as the one you're using (well, intend to use) on your web-page the
browser won't even get notified that the key in question was pressed
let alone have chance to react on it. And because every user is free to
define her/his favourite hotkeys there's no chance to use a set of
supposedly unused access keys for your web-page (even if there wouldn't
be the usual issues with browser incompatibilites).

To make a long story short: While access keys are a good idea in theory,
in practise there's no guarantee whatsoever that they will work anywhere
(except, may be, the developers own computer).

--
Matthias
/"\
\ / ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
X - AGAINST M$ ATTACHMENTS
/ \
Jun 27 '08 #5

P: n/a
Matthias Watermann wrote on 11 mei 2008 in comp.lang.javascript:
On Sun, 11 May 2008 10:06:30 +0000, Evertjan. wrote:
>MikeB wrote on 10 mei 2008 in comp.lang.javascript:
>>You may notice that in that I have mentioned that I have found and
tried using accesskey and that the results were erratic and
unpredictable.

[...]
The word "Erratic" I would preserve for inconsistent behavour even
after thorough testing of your programme on each targeted browser.
Building for cross browser compatibility is a teduous task.

Unfortunately it's not "just" a (cross-)browser issue. There's
something else involved: the respective GUI. I stumbled over this
problem some years ago when some users where quite happy with the
pages' access keys while others complained that those access keys were
misleading and wouldn't work. I was able able to find two users with
the very same browser, the same OS and even the same GUI. However,
what was working on one computer didn't at the other's. After
experimenting and changing the access keys we finally figured out what
the problem was: The GUI-setup allowed for defining hotkeys for
whatever purpose (like invoking programs or switching desktops). And
if such a GUI-based hotkey happens to be the same as the one you're
using (well, intend to use) on your web-page the browser won't even
get notified that the key in question was pressed let alone have
chance to react on it. And because every user is free to define
her/his favourite hotkeys there's no chance to use a set of supposedly
unused access keys for your web-page (even if there wouldn't be the
usual issues with browser incompatibilites).

To make a long story short: While access keys are a good idea in
theory, in practise there's no guarantee whatsoever that they will
work anywhere (except, may be, the developers own computer).
Good point, Matthias.

This leaves us with no other option than not to use the Alt and detect
the keys by the onkeydown or onkeypress of the page and also of the
relevant input fields and go from there.

To the newbee OP: do not follow this advice in your first year.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.