A Basic Submission Event
For the submit event of the form, the input type can take input type equal to submit or button type equal to submit. Here, we are going to use anb alert() for popping up our message “Mildaintrainings“. Also, it is important that we should use CSS for an appealing look. Here, only the background-color property is taken into consideration. One can add more things to it if required. For using the onsubmit function, the code is mentioned below:
Conducting Form Validations
The form validation script uses the onsubmit() event of the form to validate the input. The browser does not trigger the onsubmit event if you call the submit method programmatically. Therefore, if the form is using the form validator script, call the onsubmit method also to trigger the validation.
For giving an overall idea about form validation, an example is given here. Here, our objective is to check whether the input from the user is a real positive number or not. So, we’ve placed our constraint along-with if-else messages for correct and incorrect inputs
Give me a Positive Integer
Usually, the form validation steps are for real-time end-user inputs and usually includes names, passwords, emails, etc.
So a few valid checks can be:
Presence of ” @ “, no character before @, Top level domains cannot start with dots, double dots are not allowed.