Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2005
    Posts
    153
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Multiple Submit Buttons and Handling Enter Key

    Hey All,

    I have the classic problem of have multiple submit buttons in a form and the enter key submitting the first one (which is never the one that's needed). Is there a way to use jQuery to force the proper reaction when enter is pressed.

    Either no reaction or submitting the proper submit would be great!

    Thanks,
    questionable

  • #2
    Regular Coder Iszak's Avatar
    Join Date
    Jun 2007
    Location
    Perth, Western Australia
    Posts
    332
    Thanks
    2
    Thanked 58 Times in 57 Posts
    And what would the proper reaction be when the enter key is pressed? Submitting the form? Or not submiting it? Or something else?

    If you want it to stop submiting the form on enter you'd do something like.
    Code:
    $().keydown(function(event){
      if (event.keyCode === 13)
      {
        return false; // cancel the form submit
      }
    });
    And you'd set the selector to say an input where you want the enter key not to trigger the form submit.

    If you want the enter to submit the other form?, simply select the form you want to submit and use jQuery's .submit() function with no parameters.

    A live example of the form would of been greatly appreciated too, because it's kinda hard to understand what exactly you want.

  • Users who have thanked Iszak for this post:

    questionable (05-13-2009)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •