Easy To Use Stock Form Validation Script
* City and State


* Check a Radio Button
radio1 radio2 radio3 radio4 radio5

* Life Story


* Series of Fields
checkbox1 checkbox2

* Password




For a much more robust form validation script, see Form Validation on Steroids.

This is a stock form validation script. To know which fields are required, this script employs a simple naming convention, where an asterisk (*) is used as the first character of the HTML name values for each required field like so:
<input type="text" name="*FieldName">
Since the script does not refer to any field by its name, you are allowed to have spaces in the name, and as you can see from the example, you can even group different field types together by giving them the same name.

I've also included a reset check, where the user will be asked for confirmation before the entire form is cleared.

So to use the script, give the fields you are requiring an asterisk as the first character in their HTML name values, and include the onsubmit and onreset statements as follows:
<form method="POST" action="YourCGIHere" onsubmit="return checkFields()" onreset="return Reset()">
NOTE: I used method="get" in my form since its action is an HTML document. You will probably need to change it to "post" if you are using a CGI script.

View the Source