Disable form auto submit on button click Disable form auto submit on button click javascript javascript

Disable form auto submit on button click


Buttons like <button>Click to do something</button> are submit buttons.

Set type="button" to change that. type="submit" is the default (as specified by the HTML spec):

The missing value default and invalid value default are the Submit Button state.


You could just try using return false (return false overrides default behaviour on every DOM element) like that :

myform.onsubmit = function (){   // do what you want  return false}

and then submit your form using myform.submit()

or alternatively :

mybutton.onclick = function () {   // do what you want   return false}

Also, if you use type="button" your form will not be submitted.


<button>'s are in fact submit buttons, they have no other main functionality. You will have to set the type to button.
But if you bind your event handler like below, you target all buttons and do not have to do it manually for each button!

$('form button').on("click",function(e){    e.preventDefault();});