Skip to main content

One of the most annoying things in developing web pages is handling the Enter Key for form submission. 'Enter Key' makes form submission so easy that users always tend to use it. The easiest and the most intuitive way is that, the user can enter some text or make some changes to the existing text and then hit "Enter Key" to submit the form.

$(document).ready(function () {

  $("input").bind("keydown", function (event) {
    var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
    if (keycode == 13) { // keycode for enter key
      // force the 'Enter Key' to implicitly click the Update button
      document.getElementById('search-btn').click();
      return false;
    } else {
      return true;
    }
  });

});