trigger HTML button by enter ENTER key

Discussion in 'Javascript' started by Matt, Mar 6, 2004.

  1. Matt

    Matt Guest

    <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!
     
    Matt, Mar 6, 2004
    #1
    1. Advertising

  2. 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)
     
    Michael Winter, Mar 6, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    779
    Jonathan N. Little
    May 15, 2008
  2. Yuval Kordov

    How to get enter key to trigger button click event/postback

    Yuval Kordov, Jan 7, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    459
    Yuval Kordov
    Jan 7, 2004
  3. BrianDH

    Enter Key H*ll, control enter key submit button

    BrianDH, Jan 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    414
    Anders Matthiessen
    Jan 12, 2005
  4. M P
    Replies:
    1
    Views:
    500
  5. Replies:
    1
    Views:
    176
    marss
    Aug 11, 2006
Loading...

Share This Page