How to stop form submission using JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

Use the return value of the function to stop the execution of a form in JavaScript.

<form onsubmit = "event.preventDefault(); myValidation();">

The JavaScript function would be like the following −

function myValidation()
   if(check if your conditions are not satisfying)
      alert("Oops! Validation failed!");
      return false;
   alert("Validations successful!");
   return true;

False would return if the form fails to submit.

Updated on 23-Jun-2020 12:02:12