473,468 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Map button on form to key on keyboard

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
5 1668
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JM | last post by:
Hi I have created a Windows Form that takes input. When the Run button is pressed the form is disabled and the code checks some files and inputs the data into an Excel worksheet (that is hidden...
2
by: DDK | last post by:
Question (using C# and ASP.NET), I have a textbox and a buttonClick on my asp.net page. I would like be able to hit the Enter button on the keyboard and have it do the same thing as the...
3
by: JV | last post by:
This is for anyone who has tackled the accessibility issue on their web site (and if you haven't, I bet you will in future). Apparently the asp:button control always renders as '<input...
7
by: ManWithNoName | last post by:
If you have a form with x input and two or more buttons, how do you control which button has preceding when the user hits the keyboard key "enter"? Currently it seems to be determined in a...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.