Here's a form validation script courtesy of The JavaScript
Source
You can find the script here:
http://javascript.internet.com/forms/basic-validation.html
1. Paste this part between your <HEAD>
</HEAD>tags.
A good place might be right after the title <TITLE></TITLE>
tags
| <SCRIPT LANGUAGE="JavaScript"> <!-- Original: wsabstract.com --> <!-- This script and many more are available free online at --> <!-- The JavaScript Source!! http://javascript.internet.com --> <!-- Begin function checkrequired(which) { var pass=true; if (document.images) { for (i=0;i<which.length;i++) { var tempobj=which.elements[i]; if (tempobj.name.substring(0,8)=="required") { if (((tempobj.type=="text"||tempobj.type=="textarea")&& tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&& tempobj.selectedIndex==0)) { pass=false; break; } } } } if (!pass) { shortFieldName=tempobj.name.substring(8,30).toUpperCase(); alert("Please make sure the "+shortFieldName+" field was properly completed."); return false; } else return true; } // End --> </SCRIPT> |
2. Add the following to the form tag <FORM>:
onSubmit="return checkrequired(this)"
The completed form tag should look like this:
<FORM METHOD="POST" ACTION="/bin/script_library/form_handler_mail"
onSubmit="return checkrequired(this)">
3. For every field you wish to require attach the word required to the field input name like this:
INPUT NAME="requiredEMAIL" TYPE="text" ......
It's a good idea to mark the required fields in some way to guide visitors filling out the form (ie different color text, an *, or the word "required")