For more information beyond this tutorial, see the Constraint validation guide. When you enter data, the web application checks it to see that the data is correct.
If the information is correct, the application allows the data to be submitted to the server and (usually) saved in a database; if the information isn't correct, it gives you an error message explaining what needs to be corrected.
When the form is submitted - either by hitting Enter or clicking on the Submit button - the to abort (cancel) the form submission. In a real-life situation you will most likely have more fields to check, and more complicated conditions, but the principle remains the same.
When you are asking a reader for their email address, you can use a simple » address validation function to make sure the address has a valid structure. Each option in a drop-down box is indexed in the array Annoyingly, there is no simple way to check which radio button out of a group is selected — you have to check through each element, linked with Boolean AND operators .
We're going to be checking the form using a function, which will be activated by the form's Validating this form would be considerably simpler than one containing radio buttons or select boxes, but any form element can be accessed.
Below are the ways to get the value from all types of form elements.
Validating form input with Java Script is easy to do and can save a lot of unnecessary calls to the server.
It can prevent people from leaving fields blank, from entering too little or too much or from using invalid characters.
One of the features of HTML5 is the ability to validate most user data without relying on scripts.