Thursday 6 December 2012

jQuery code to disable "Enter" key

Got a strange requirement from my client that whenever the "Enter" key is pressed on the page, the page should not be submitted. It should only be submitted when user clicks the submit button using mouse.

Well, this was pretty simple and easy with jQuery. I have implemented it in 2 mins and thought of sharing with all my readers.

Below jQuery code will disable the "Enter" key on the page.



$("#form").keypress(function(e) {

  if (e.which == 13) {

    return false;

  }

});    

No comments:

Post a Comment

Do you think it could be useful for you? Share your thoughts with us!