or since each team has the same index for each select box, you can use the selectedIndex property for checking instead of text.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--Begin
function validate(obj){
if((obj.nbateam1.selectedI
alert("You cannot choose the same team");
return false;
}
return true;
}
//End-->
</script>
</head>
<body>
<form name="form1" method="post" action="" onsubmit="return validate(this);">
<Select name=nbateam1>
<option>Lakers</option>
<option>Celtics</option>
<option>Spurs</option>
</Select>
<Select name=nbateam2>
<option>Lakers</option>
<option>Celtics</option>
<option>Spurs</option>
</Select>
<Select name=nbateam3>
<option>Lakers</option>
<option>Celtics</option>
<option>Spurs</option>
</Select>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
Main Topics
Browse All Topics





by: jaysolomonPosted on 2004-01-06 at 20:21:20ID: 10058898
how about this
ctedIndex] .text; m1"]); m2"]); m3"]);
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--Begin
function getSelectText(selObj){
return selObj.options[selObj.sele
}
function validate(fObj){
var selTxt1 = getSelectText(fObj["nbatea
var selTxt2 = getSelectText(fObj["nbatea
var selTxt3 = getSelectText(fObj["nbatea
if(selTxt1 == selTxt2 || selTxt1 == selTxt3){
alert("You cannot choose the same team");
return false;
}
if(selTxt2 == selTxt1 || selTxt2 == selTxt3){
alert("You cannot choose the same team");
return false;
}
if(selTxt3 == selTxt1 || selTxt3 == selTxt2){
alert("You cannot choose the same team");
return false;
}
return true;
}
//End-->
</script>
</head>
<body>
<form name="form1" method="post" action="" onsubmit="return validate(this);">
<Select name=nbateam1>
<option>Lakers</option>
<option>Celtics</option>
<option>Spurs</option>
</Select>
<Select name=nbateam2>
<option>Lakers</option>
<option>Celtics</option>
<option>Spurs</option>
</Select>
<Select name=nbateam3>
<option>Lakers</option>
<option>Celtics</option>
<option>Spurs</option>
</Select>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>