473,834 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
+ 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 1698
MikeB wrote on 10 mei 2008 in comp.lang.javas cript:
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.javas cript:
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.javas cript:
>You may notice that in that I have mentioned that I have found and
tried using accesskey and that the results were erratic and
unpredictabl e.

[...]
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 incompatibilite s).

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.javas cript:
On Sun, 11 May 2008 10:06:30 +0000, Evertjan. wrote:
>MikeB wrote on 10 mei 2008 in comp.lang.javas cript:
>>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 incompatibilite s).

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
1816
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 so that I cannot watch as it gets filled up). When it is done it saves the Excel file. I find that if I go into another program while it's trying to work on the Excel spreadsheet that not all of the data appears (missing data!). If I click...
2
10210
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 buttonClick. In other words how do you get Enter button on the key board to perform the same operation as a button click event. Any help would be great, Thanks
3
2068
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 type="submit" ....' (a.k.a. submit button) and this can have a big impact on your web site's keyboard handling. Default IE behavior when you have the keyboard focus on an edit field is to find the first submit button and trigger a click event on it ...
7
3149
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 hierarchical manner. E.g. <form>
0
9649
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10799
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10515
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10554
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10224
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9338
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5629
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5799
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3084
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.