Prevent Enter from Submitting Form (jQuery)


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $('.no-enter').keypress(function(e){ //Stop form fields with class 'no-enter' from submitting the form when the user presses enter
  2. if(e.which == 13){ //Identifies the enter key as the key pressed
  3. e.preventDefault(); //Stops the enter key from performing default function
  4. alert('no enter'); //Put whatever you want to happen here
  5. }
  6. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.