Basic Validation | JavaScriptSource

Basic Validation

JavaScriptSource Staff Apr 14, 1999

General

This is a simple method to require your visitors to fill out certain fields in a form. Just add the word "required" to each required field's name and your visitor must fill it out to submit the form.


Name:
E-mail:
Comments:

Notes

Source Code

Paste this source code into the designated areas.

External file

Paste this code into an external JavaScript file named: basicValidation.js


Head

Paste this code into the HEAD section of your HTML document.


Body

Paste this code into the BODY section of your HTML document


Leave a Response

(13 comments)

Hi, Thanks for the script above, do you know how I could validate a group of select lists? The form I'm working on has 10 select lists and I want the viewer to select a minimum of 1 item out of those 10 select lists before the form can be submited. Would be grateful for your help, thank you. Pete

Pete Oct 1, 2012

Just what I needed thanks!

M Yelverton Nov 18, 2008

Thanks for the sript. Because I need my field names to be what they are and not have "required" in front of them, I made a change to the script. I gave each form element an ID of required_xxx where xxx is any prompt - works with spaces and seems much friendlier than the field name.[br /][br /]The only change tot the js file was replacing "name" with "id".[br /][br /]Thanks for the script.

Liz Maher Aug 5, 2008

If you don't want to change the name of the field, you can use the basic validation script on the "ID" tag instead. Here are the changes to the basicValidation script:[br /][br /]...[br /]if (tempobj.id.substring(0,8)=="required") {[br /]... shortFieldName=tempobj.id.substring(8,30).toUpperCase();[br /][br /][br /]Inside of the HTML tag:[br /][br /]<input id="requiredLogin Name" type=text name="Login_Name" value="">[br /][br /]HAVE FUN and thanks for the basicValidation script!!!

db Jun 18, 2008

This script for for validation purposes only. You will need to find a different type of script for that.

Lee Nov 6, 2007