This post will discuss how to prevent an HTML form from being submitted in JavaScript and jQuery.

The simplest solution to prevent the form submission is to return false on submit event handler defined using the onsubmit property in the HTML <form> element.

HTML



Edit in JSFiddle

 
Alternatively, you can call the Event.preventDefault() to prevent the default action on a form submission from executing.

HTML



Edit in JSFiddle

 
Note that it is always a good practice to separate JavaScript from HTML markup, but the above solution fails to do so. A better solution is to bind an event handler to the “submit” JavaScript event. The submit event fires whenever the user submits a form.

JS


HTML



Edit in JSFiddle

That’s all about preventing an HTML </form> from being submitted in JavaScript and jQuery.