Enter key do not give submit

12

How to make the enter key not give submit on a form?

Example: in an input pressing enter nothing happens.

Today, if you press enter , the browser gives submit , and you clicked the submit button.

    
asked by anonymous 14.12.2015 / 20:24

2 answers

19

You can replace the handler with the default behavior:

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

Or, in the Form tag:

<form onsubmit="return false;">

Source.

    
14.12.2015 / 20:26
8

It also gives:

 $('#form').bind('submit', false);

 $('button#submit').click(function()
 {
    $('#form').submit();
 });

This will cause the form to be sent only when you click the submit button.

    
14.12.2015 / 20:29