function validateForm() {
var x = document.forms["myForm"]["fname"].value;
if (x == null || x == "") {
alert("Name must be filled out");
return false;
}
}
<form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post">
Name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>
This code validates an HTML form. I can't understand what onsubmit="return validateForm()" means. How does it prevent the page from completing the form submission? I understand the logic behind the validation,but I do not understand the procedure by which it stops the submission.