Web Analytics Made Easy -
StatCounter Multiple Submit Buttons and Handling Enter Key - CodingForum

Announcement

Collapse
No announcement yet.

Multiple Submit Buttons and Handling Enter Key

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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.

    Comment

    Working...
    X