Answers for "avoid enter submit form"

6

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>
Posted by: Guest on August-26-2020
1

jquery avoid enter submit

$(document).ready(function() {
  $(window).keydown(function(event){
    if(event.keyCode == 13) {
      event.preventDefault();
      return false;
    }
  });
});
Posted by: Guest on June-12-2020
1

prevent default on enter press

/* Jquery method */
$('#form-input').on('keypress', (e) => { 
  const keyPressed = e.keyCode || e.which; 
  if (keyPressed === 13) {
    e.preventDefault();
    return false; 
  }
  /* or */
  return keyPressed !== 13;
});

/* or */
$('#form-input').on('keypress', (e) => return e.keyCode !== 13);

/* HTML Inline */
<form ... onkeydown="return event.keyCode !== 13;">
Posted by: Guest on January-31-2021

Browse Popular Code Answers by Language