How to prevent form submit on enter using jQuery

I had a client that pressed enter after typing in a form by mistake and kept saying that my script had an error.
After disabling the form submission on enter key the problem vanished 🙂

Prevent form submit on enter script :

$(document).keydown(function(evt) {
   var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
   if (keyCode == 13) {
     return false;
   }
});

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.