Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

trigger HTML button by enter ENTER key

11 views
Skip to first unread message

Matt

unread,
Mar 6, 2004, 11:12:38 AM3/6/04
to
<input type="button" onClick="doSomething()">

When the user click HTML button, it will launch doSomething(). But I
want the user enter ENTER key, it will have same effect.

Please advise. Thanks!

Michael Winter

unread,
Mar 6, 2004, 2:01:58 PM3/6/04
to
On 6 Mar 2004 08:12:38 -0800, Matt <jrefa...@hotmail.com> wrote:

> <input type="button" onClick="doSomething()">
>
> When the user click HTML button, it will launch doSomething(). But I
> want the user enter ENTER key, it will have same effect.

If the button has focus, pressing enter will invoke an onclick event. If
some other control (in a form) has focus, the form's submit button will
receive the event.

As I see it, if you do want to invoke an event on an arbitrary control,
you'll have to handle the onkeydown event on *every* control that might be
active when Enter is pressed and fire the event yourself. That's a lot of
work.

Mike

--
Michael Winter
M.Wi...@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)

0 new messages