Click here to get back home

Using keyboard keys to activate buttons

 HomeNewsGroups | Search | About
 comp.infosystems.www.authoring.html    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Using keyboard keys to activate buttons MikeB 05-06-2008
Posted by MikeB on May 6, 2008, 3:30 pm
Please log in for more thread options
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

Posted by Jukka K. Korpela on May 7, 2008, 2:49 am
Please log in for more thread options
Scripsit MikeB:

> 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?

That's not a short question, really. And questions don't get any
shorter, or any simpler, just by calling them "short".

> 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.

Did you do it? URL? The odds are that it is far more important to
analyze the basic solution than to invent new complexities. So how did
the page look like when scripting was disabled? Let me guess... a form,
with a button, and clicking on the button does nothing? No explanation
anywhere?

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

It would be an exercise in futility, since the calculator would be
inferior even to the _simple_ (as opposite to "scientific") mode of the
Windows Calculator.

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

But you didn't learn yet that the way to share your HTML document is to
upload it on a web server and post the URL?

> 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.

You can do that, with the usual caveats, using JavaScript. That's
off-topic here. There's the HTML issue of associating scripts with
elements, with attributes like onkeypress, but that's really the trivial
side of the matter (and the details depend on the approach).

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

Indeed. So forget them. To begin with, some browsers interpret
accesskeys as _activating_ a button, some just as _focusing_ on it.
Accesskey attributes in HTML are widely regarded as a failure, by people
who have tested the idea and analyzed the design. They are detrimental
to accessibility, since they may mask out built-in access key
assignments in browsers and other software.

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

You did something wrong. Wrong expectations?

> 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).

You did something wrong. Maybe on line 42?

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/


Posted by MikeB on May 8, 2008, 3:27 pm
Please log in for more thread options
> Scripsit MikeB:
>
> > 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?
>
> That's not a short question, really. And questions don't get any
> shorter, or any simpler, just by calling them "short".
>
I guess we'll just have to differ. I thought that was a short question
that was potentially answerable.

As I get to read about HTML, I realize there seems to be hardly any
issue that is either "short" or "simple", but still, one can hope.

> > 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.
>
> Did you do it? URL? The odds are that it is far more important to
> analyze the basic solution than to invent new complexities. So how did
> the page look like when scripting was disabled? Let me guess... a form,
> with a button, and clicking on the button does nothing? No explanation
> anywhere?

I did it. But we don't upload our pages to a server, we simply write
them in NotePad and then open them in IE or FireFox on our own
computers.

The instructor showed us how to register a domain name, but we've not
yet begun to upload any real pages to that.

>
> > I thought it would be interesting to write an entire calcualtor
> > (similar to the one that comes with Windows) as an HTML page.
>
> It would be an exercise in futility, since the calculator would be
> inferior even to the _simple_ (as opposite to "scientific") mode of the
> Windows Calculator.

Of course it is, but I learned something by writing it. I don't think
as a beginner I can start out and only write things that are going to
be better than the existing stuff out there. I think that's
unrealistic.

>
> > I got most of it right, I have buttons and an input field and buttons
> > to do the calculations.
>
> But you didn't learn yet that the way to share your HTML document is to
> upload it on a web server and post the URL?

Unfortunately no.

But I thought, what the heck, I might try it and see if you woulod
offer a useful suggestion.

So here it is: http://fmechess.org/demo/calculator.html

>
> > 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.
>
> You can do that, with the usual caveats, using JavaScript. That's
> off-topic here. There's the HTML issue of associating scripts with
> elements, with attributes like onkeypress, but that's really the trivial
> side of the matter (and the details depend on the approach).
>

Yes, I did use JavaScript. That was what the lesson was all about.


> > I found that I could specify access keys in the HTML, but that works
> > weird.
>
> Indeed. So forget them. To begin with, some browsers interpret
> accesskeys as _activating_ a button, some just as _focusing_ on it.
> Accesskey attributes in HTML are widely regarded as a failure, by people
> who have tested the idea and analyzed the design. They are detrimental
> to accessibility, since they may mask out built-in access key
> assignments in browsers and other software.

So "forgetting accesskeys" what else do I use?

>
> > In Firefox, it doesn't seem to work at all.
>
> You did something wrong. Wrong expectations?

Perhaps. I tested the same set of keystrokes as that got some results
in IE.


>
> > 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).
>
> You did something wrong. Maybe on line 42?

Ha ha... you are too funny. I didn't know the Finnish people has such
an acute sense of humor...



Posted by Jukka K. Korpela on May 9, 2008, 12:37 am
Please log in for more thread options
Scripsit MikeB:

>>> 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?
>>
>> That's not a short question, really. And questions don't get any
>> shorter, or any simpler, just by calling them "short".
>>
> I guess we'll just have to differ.

On which of my statements? If you call a 30-word question short, then we
do differ, and you are wrong. If you think that a question gets shorter
or simpler by calling it "short", then we do differ, and you are very
wrong.

> As I get to read about HTML, I realize there seems to be hardly any
> issue that is either "short" or "simple", but still, one can hope.

Most issues about HTML are both short and simple, but there's little
need to _discuss_ them.

> I did it. But we don't upload our pages to a server,

You really shouldn't ask for help in HTML authoring for the WWW in
public before you know how to upload a page on a server and understand
the importance of posting a URL.

> The instructor showed us how to register a domain name, but we've not
> yet begun to upload any real pages to that.

A ten-year old kid can upload a real page on a free server with her left
hand. Registering a domain name has nothing to do with it.

> But I thought, what the heck, I might try it and see if you woulod
> offer a useful suggestion.
>
> So here it is: http://fmechess.org/demo/calculator.html

That's not what I asked for. I asked for the URL of the _basic_
exercise.

> So "forgetting accesskeys" what else do I use?

Use the Force. And do things in the right order. First, create a page
that works without scripting. Then test it. Test it again - you surely
skipped some essential test. Then, time permitting, you might consider
whether you wish to add some optional enhancement using client-side
scripting. - In reality, time seldom permits, and in any case, scripting
as such is OFF-TOPIC in this group.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/


Posted by MikeB on May 9, 2008, 9:04 am
Please log in for more thread options
> Scripsit MikeB:
>
> >>> 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?
>
> >> That's not a short question, really. And questions don't get any
> >> shorter, or any simpler, just by calling them "short".
>
> > I guess we'll just have to differ.
>
> On which of my statements? If you call a 30-word question short, then we
> do differ, and you are wrong. If you think that a question gets shorter
> or simpler by calling it "short", then we do differ, and you are very
> wrong.

Please tell me, sir. How many words am I permitted in a short
question?

Are all questions over the above limit "long" questions or do you have
several scales of grading the length of questions?

>
> > As I get to read about HTML, I realize there seems to be hardly any
> > issue that is either "short" or "simple", but still, one can hope.
>
> Most issues about HTML are both short and simple, but there's little
> need to _discuss_ them.
>
> > I did it. But we don't upload our pages to a server,
>
> You really shouldn't ask for help in HTML authoring for the WWW in
> public before you know how to upload a page on a server and understand
> the importance of posting a URL.

Who made you the boss of what I should or shouldn't do? If you don't
want to advise, just let it be, I can deal with no-one answering a
question.


>
> > The instructor showed us how to register a domain name, but we've not
> > yet begun to upload any real pages to that.
>
> A ten-year old kid can upload a real page on a free server with her left
> hand. Registering a domain name has nothing to do with it.

I'm an old geezer. We didn't grow up with the right skillz.

>
> > But I thought, what the heck, I might try it and see if you woulod
> > offer a useful suggestion.
>
> > So here it is:http://fmechess.org/demo/calculator.html
>
> That's not what I asked for. I asked for the URL of the _basic_
> exercise.
>
> > So "forgetting accesskeys" what else do I use?
>
> Use the Force. And do things in the right order. First, create a page
> that works without scripting. Then test it. Test it again - you surely
> skipped some essential test. Then, time permitting, you might consider
> whether you wish to add some optional enhancement using client-side
> scripting. - In reality, time seldom permits, and in any case, scripting
> as such is OFF-TOPIC in this group.
>

Thanks for all you help. NOT.


Similar ThreadsPosted
Function Keys as shortcuts? February 12, 2007, 2:47 pm
Marking up keyboard shortcuts September 2, 2004, 12:59 pm
Keyboard scrolling in web pages? February 5, 2005, 9:21 am
textarea problem: keyboard focus doesn't follow mouse focus/click June 13, 2008, 10:05 am
Order of buttons? October 6, 2005, 9:37 am
Help With RSS Red Feed Buttons October 21, 2006, 3:56 pm
Font-size buttons October 6, 2005, 9:42 am
Forward and Back buttons? May 14, 2005, 8:40 am
What would cause radio buttons to not be clickable? May 1, 2006, 3:56 pm
Image overlay for non square buttons September 8, 2004, 11:52 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap