FF1+ IE5+ Opr7+

Required field(s) validation

Author: L K Toh | Homepage

Note: Updated Jan 16th, 2003 to version 1.1. Now checks radio buttons as well.

Description: One of the most popular form validation tasks is to check that important fields within a form have been filled out by the user. This is a generic script that will do just that, by verifying that mandatory fields are filled in before form submission. If one or more of the required fields are empty, a popup dialog will appear showing the omitted fields. Updated to check radio buttons as well.

Demo: All the below fields must be entered:

First Name:
Last Name:
Sex: Male Female
Age:


Directions: Developer's View

Simply add the below to the <BODY> of your page. It contains the validation script, plus a sample form following it:

Select All

As shown in the code above, to apply the validation script to your form, you should:

1) Inside the <FORM> tag itself of your form, input the onSubmit event handler: onsubmit="return formCheck(this);"
2) Give all the mandatory form elements a unique name (ie: <textarea name="Address">)
3) Finally inside the script, input these names as instructed by the documentation of script.

Wordpress Users: Step by Step instructions to add ANY Dynamic Drive script to an entire Wordpress theme or individual Post