Validating form fields with javascript

The form will include one text field called "Your Name", and a button.Our validation script will ensure that the user enters their name before the form is sent to the server. Try pressing the Send Details button without filling anything in the "Your Name" field.

validating form fields with javascript-44validating form fields with javascript-29validating form fields with javascript-58

Then, after they fill in the "Name" field and press "Send Details" again, it will prompt them for the "Gender" field.

As a finishing touch, try making the script move the cursor to the field that needs filling in each time ( I'm hoping you can provide me with some guidance.

Our example is very simple as it only checks one field.

Let's expand this example with a more complex function that checks lots of form fields.

Finally, the "Terms and Conditions" checkbox is validated.

Last modified 05-Jan-2017 10:06