Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-14-2009, 06:07 PM   PM User | #1
questionable
Regular Coder

 
Join Date: Jun 2005
Posts: 153
Thanks: 26
Thanked 0 Times in 0 Posts
questionable is an unknown quantity at this point
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
questionable is offline   Reply With Quote
Old 04-15-2009, 05:13 AM   PM User | #2
Iszak
Regular Coder

 
Iszak's Avatar
 
Join Date: Jun 2007
Location: Perth, Western Australia
Posts: 332
Thanks: 2
Thanked 58 Times in 57 Posts
Iszak is an unknown quantity at this point
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.
Iszak is offline   Reply With Quote
Users who have thanked Iszak for this post:
questionable (05-13-2009)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:32 PM.


Advertisement
Log in to turn off these ads.