Home > Development > Quick Tip: Use JQuery to submit a TextBox.

Quick Tip: Use JQuery to submit a TextBox.

February 24th, 2011

imageSubmitting a search box when <Enter> is pressed is a nice usability feature to provide.  Unfortunately, ASP.NET Web Forms and it’s requirement for a single <form> tag breaks this expected behavior when there is more than one submit button on the page.   This can be easily fixed with a JavaScript and JQuery.   Listening to the keydown event on the TextBox the ‘Go’ submit button can be triggered when <Enter> is pressed.

jQuery("#searchTextBox").keydown(function (event) {
    if (event.keyCode && event.keyCode == '13') {
        jQuery("#searchButton").click();
        return false;
    } else {
        return true;
    }
});

Development , ,

  1. No comments yet.
  1. No trackbacks yet.