prevent return from submitting form code example

Example 1: html disable enter submit

//per form disabling
<form ... onkeydown="return event.key != 'Enter';">
 
  
//or with jquery  
<script>
 $(document).on("keydown", "form", function(event) { 
    return event.key != "Enter";
});
 </script>

Example 2: jquery avoid enter submit

$(document).ready(function() {
  $(window).keydown(function(event){
    if(event.keyCode == 13) {
      event.preventDefault();
      return false;
    }
  });
});

Example 3: prevent button from submitting form

function myFunc(e){
       e.preventDefault();
}

Example 4: prevent button form submit

<button type="button">Button</button>

Tags:

Html Example