form prevent submit code example

Example 1: javascript prevent form submit

<form name="foo" onsubmit="return false">

Example 2: prevent button from submitting form

function myFunc(e){
       e.preventDefault();
}

Example 3: prevent form submission on onsubmit function calls

returning false here won't be executed and the form will be submitted either way. You should also call preventDefault to prevent the default form action for Ajax form submissions.

function mySubmitFunction(e) {
  e.preventDefault();
  someBug();
  return false;
}

Get more references : https://stackoverflow.com/questions/3350247/how-to-prevent-form-from-being-submitted

Example 4: prevent button form submit

<button type="button">Button</button>

Example 5: javascript do not submit form

alert("hello world");
alert("it is a test");