PDA

View Full Version : Multiple Submit Buttons and Handling Enter Key


questionable
04-14-2009, 07:07 PM
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

Iszak
04-15-2009, 06:13 AM
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.

$().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.