Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > trigger HTML button by enter ENTER key

Reply
Thread Tools

trigger HTML button by enter ENTER key

 
 
Matt
Guest
Posts: n/a
 
      03-06-2004
<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!
 
Reply With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      03-06-2004
On 6 Mar 2004 08:12:38 -0800, Matt <> 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
d (replace ".invalid" with ".uk" to reply)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
disabling the ENTER button to trigger a button? paul814@excite.com HTML 2 05-15-2008 03:28 PM
trigger click on button when Enter Key is pressed samuelberthelot@googlemail.com Javascript 1 08-11-2006 09:29 AM
Enter Key H*ll, control enter key submit button BrianDH ASP .Net Web Controls 3 01-12-2005 08:29 PM
Replace Tab Key to Return Key (Enter Key) from Web Forms? M P ASP General 1 08-06-2004 08:32 AM
How to get enter key to trigger button click event/postback Yuval Kordov ASP .Net Web Controls 0 01-07-2004 06:47 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57