How to control which submit button to use when hit enter

Discussion in 'Javascript' started by Martin, Apr 10, 2009.

  1. Martin

    Martin Guest

    Is there any way (using javascript) to "click" a specific "submit"
    button when the user hits the <Enter> key?

    From what I read, hitting <Enter> is supposed to send the form via the
    "first" submit button on the page but I find that, in IE at least, my
    server-side scripting doesn't receive any submit button.
     
    Martin, Apr 10, 2009
    #1
    1. Advertising

  2. Martin

    Mike Duffy Guest

    Martin <> wrote in
    news::

    > Is there any way (using javascript) to "click" a specific "submit"
    > button when the user hits the <Enter> key?
    >
    > From what I read, hitting <Enter> is supposed to send the form via the
    > "first" submit button on the page but I find that, in IE at least, my
    > server-side scripting doesn't receive any submit button.


    I'm not sure about pre-picking a particular button, but why not just use
    the same event handler for your default button AND the return key?

    In the example, "dh" is the default form handler, which will execute if
    button yy is pushed, or if the return key is pressed. "hh" will only be
    called if button xx is pressed.

    You can also designate other functions to fire when any particular key is
    pressed, just by changing the value of 13.


    <form name="myform" action="" method="post">

    <input title="tt" type="text" name="inputbox" value="ib" maxLength="10"
    size="10" onkeypress="if (event.keyCode==13) {dh(this.form);};" >

    <input type="button" name="button" value="xx" onClick="hh(this.form);" >

    <input type="button" name="button" value="yy" onClick="dh(this.form);" >

    </form>
     
    Mike Duffy, Apr 10, 2009
    #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. Curt_C [MVP]

    Default button when hit Enter

    Curt_C [MVP], Jan 12, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    361
    Harry
    Jan 13, 2004
  2. William Buchanan

    Form submit in textbox when enter key hit

    William Buchanan, Apr 5, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    4,365
    William Buchanan
    Apr 7, 2006
  3. BrianDH

    Enter Key H*ll, control enter key submit button

    BrianDH, Jan 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    404
    Anders Matthiessen
    Jan 12, 2005
  4. Guest
    Replies:
    2
    Views:
    1,606
    Guest
    Oct 25, 2004
  5. HopfZ
    Replies:
    0
    Views:
    576
    HopfZ
    Aug 28, 2006
Loading...

Share This Page