<html> <head> <title> Check Submit Form </title> </head> <body> <form id="user_form" onsubmit="return ValidationEvent()"> <input type="text" id="username"></input> <input type="text" id="password"></input> <input type="submit" id="submit_button"></input> </form> </body> </html>
The line of code which is becoming the decision on the form submit prevention is the following line of code :
<form id="user_form" onsubmit="return ValidationEvent()">
Based on the submit event action, the method ValidationEvent will be executed and the process of validation will be started with checking the username whether it is empty or not. If it is empty the submission form will be stop and it will not going futher. It is specified by the following line of code :
if(document.getElementById("username").value == "")
The conditional if above is for checking whether or not the input type text HTML element is empty. If it is empty, it will alert for giving a message informing that the input type text HTML element is empty. Furthermore, for the process in the method named ‘ValidationEvent’ stop so it is not need to be further validated, the following line of code is written after :
So, the process will stop and there will be no further validation process which in the above snippet code context it is for validating the password.