Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Validation (One field enables/disables validation of another)

Status
Not open for further replies.

OutInLeftField

Programmer
Apr 30, 2002
37
US
I have a form that has States (2 char) and Zip code (10 char for 5 and 4 extension). What i need to do is check to see if the state field is one of the 50 states and military "state" locations then turn on javascript validation routine on Zip code field. If the location is not within the states then ignore whatever data is entered in Zip field...
 
What I am trying to do is check to see what state code the end user puts in. If the state code (IL, IA, for example) matches any of the 50 state codes for USA, then the code will "turn on" validation routine for the zipcode form field-making the zipcode required. Otherwise the zipcode field can be skipped.

I'm using Javascript as follows:

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin ---->
// Preload images
var empty = new Image(); empty.src = "fieldempty.gif";
var email = new Image(); email.src = "emailerror.gif";


var haveerrors = 0;
function showImage(imagename, imageurl, errors) {
document[imagename].src = imageurl;
if (!haveerrors && errors) haveerrors = errors;
}

function validateFormS(f) {
haveerrors = 0;

(f.st.value == "") // validate state
? showImage("stateerror", "fieldempty.gif", true)
: showImage("stateerror", "blankimage.gif", false);


I will need one for Zip code.

(f.zip.value == "") // validate zip code
? showImage("ziperror", "fieldempty.gif", true)
: showImage("ziperror", "blankimage.gif", false);

If the value for st is one of the 50 states then the f.zip.value section of code must be activated.

thank you.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top