I basically needed the update button to be the default action on clicking enter in the form, but there were multiple submit buttons in my form and they weren’t in the order I needed due to UI design. This was a quick and dirty solution to select an html submit button and make it the default when a user clicks enter from certain or all input elements on the form. It could be tweaked to give specific behavior to specific types of input boxes, such as invoking a tab on enter in between required elements, but the general idea is using jQuery to click the default button when the user hits enter.
$(function() {
$("form input").keypress(function (e) {
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
$('button[type=submit] .default’).click();
return false;
} else {
return true;
}
});
});
This entry was posted on Thursday, April 24th, 2008 at 9:43 am and is filed under DOM.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
Comments
Web 2.0 Announcer 10:12 am on May 5, 2008
Default html button submit on enter with JQuery…
[...]This was a quick solution to select an html submit button and make it the default when a user clicks enter from certain or all input elements on the form using jQuery.[...]…
Leave a Comment