Stop submitting form while hitting enter button

Use below script if you would like to stop submitting form while pressing enter button in the HTML form. This is quite useful while you have many JavaScript control and AJAX for loading data from database or another page or loading data from database.

document.onkeypress = stopSubmit;
function stopSubmit() {
  if (window.event.keyCode == 13){
     event.cancel = true;

Leave a Reply

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