The easiest javascript form validation

Logo design tips

This week, I have been been creating an online form for a current client and I was looking for a Javascript form validation script. Surprise, Surprise I found the easiest one! And I thought I should share it.

This form validation script is so easy, it’s done in four easy steps.

1.You create the external .js file and include:

/* This script and many more are available free online at
The JavaScript Source!!
Created by: | */
function checkrequired(which) {
var pass=true;
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (,8)==”required”) {
if (((tempobj.type==”text”||tempobj.type==”textarea”)&&
tempobj.selectedIndex==0)) {
if (!pass) {,30).toUpperCase();
alert(“The “+shortFieldName+” field is a required field.”);
return false;
} else {
return true;

2. Then you add the link to external script tag into the head of your document.

3. In your form you add the following:

<form onSubmit=”return checkrequired(this)”>

4. In the actual “name” of each individual field in the form, you add the word ‘required’ with no spaces in front of the current name.

It was so easy I thought it would never work.

Original form validation script here

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s