WoG
08-31-2004, 05:58 PM
I'm trying to validate a form select box, and am validating based on the values of that select box after it's selected.
What I need to make sure is:
Value 1 of the gender field AND value 3 of the sport field are selected- If the ARE, then return true.
Do I need to pass this function 2 selectObj's in the declaration, since I am looking at 2 different form objects inside the function? Is my syntax correct for the AND in the IF statement? Should I use a Select CASE or the IF?
I'm not getting this to work. Any help would be appreciated.
Here is my fuction:
function SportGenderCheck(selectObj)
{
Select Case
if(document.athletic_prospect.gender.selectedIndex == "2" && document.athletic_prospect.sport.selectedIndex == "1") return true;
else if (document.athletic_prospect.gender.selectedIndex == "2" && document.athletic_prospect.sport.selectedIndex == "3") return true;
else if (document.athletic_prospect.gender.selectedIndex == "2" && document.athletic_prospect.sport.selectedIndex == "4") return true;
else if (document.athletic_prospect.gender.selectedIndex == "2" && document.athletic_prospect.sport.selectedIndex == "6") return true;
else if (document.athletic_prospect.gender.selectedIndex == "1" && document.athletic_prospect.sport.selectedIndex == "12") return true;
else if (document.athletic_prospect.gender.selectedIndex == "1" && document.athletic_prospect.sport.selectedIndex == "8") return true;
else if (document.athletic_prospect.gender.selectedIndex == "1" && document.athletic_prospect.sport.selectedIndex == "9") return true;
}
and here is the call:
if (SportGenderCheck(formObj.gender))
alert("The sport you selected does not match the correct gender");
What I need to make sure is:
Value 1 of the gender field AND value 3 of the sport field are selected- If the ARE, then return true.
Do I need to pass this function 2 selectObj's in the declaration, since I am looking at 2 different form objects inside the function? Is my syntax correct for the AND in the IF statement? Should I use a Select CASE or the IF?
I'm not getting this to work. Any help would be appreciated.
Here is my fuction:
function SportGenderCheck(selectObj)
{
Select Case
if(document.athletic_prospect.gender.selectedIndex == "2" && document.athletic_prospect.sport.selectedIndex == "1") return true;
else if (document.athletic_prospect.gender.selectedIndex == "2" && document.athletic_prospect.sport.selectedIndex == "3") return true;
else if (document.athletic_prospect.gender.selectedIndex == "2" && document.athletic_prospect.sport.selectedIndex == "4") return true;
else if (document.athletic_prospect.gender.selectedIndex == "2" && document.athletic_prospect.sport.selectedIndex == "6") return true;
else if (document.athletic_prospect.gender.selectedIndex == "1" && document.athletic_prospect.sport.selectedIndex == "12") return true;
else if (document.athletic_prospect.gender.selectedIndex == "1" && document.athletic_prospect.sport.selectedIndex == "8") return true;
else if (document.athletic_prospect.gender.selectedIndex == "1" && document.athletic_prospect.sport.selectedIndex == "9") return true;
}
and here is the call:
if (SportGenderCheck(formObj.gender))
alert("The sport you selected does not match the correct gender");