N
nadesico
I have a multiple dropdown box with the following selections: Individual,
Group, Parent, Family, Teacher, Other, and also have a text box that the user
needs to fill in if 'other' is selected. I am trying to use javascript to
ensure that if the user selects something other than 'other', and fills in
the text box, that an error message appears. Any help would be greatly
appreciated.
<!--
function Validate(){
i=0
chosen = ""
var str = document.MTPSFY10.ServiceFormat_OtherDesc.value .replace(/\s/g,'');
for(i=0; i<document.MTPSFY10["ServiceFormat"].length; i++){
if(document.MTPSFY10["ServiceFormat"].selected){
chosen = chosen + document.MTPSFY10["ServiceFormat"].value
if(chosen !== "06" && str !== ""){
alert("Please Fill In Service Format Other Description");
document.MTPSFY10["ServiceFormat"].focus();
return false;}
}
}
return true
}
//-->
</script></head>
<body>
<form name="MTPSFY10" method="POST" onsubmit="return Validate();"
action="--WEBBOT-SELF--">
<table border="1" cellspacing="0" cellpadding="2" width="616">
<tr>
<td width="316"><select size="6" name="ServiceFormat" multiple>
<option value="01">Individual</option>
<option value="02">Group</option>
<option value="03">Parent</option>
<option value="04">Family</option>
<option value="05">Teacher</option>
<option value="06">Other</option>
</select></td>
<tr>
<td width="316">Other Description: <input type="text"
name="ServiceFormat_OtherDesc" size="20" maxlength=50></td>
</tr>
</table>
<p> </p>
<p><input type="submit" value="Submit" name="B1">
</p>
</form>
</body>
</html>
Group, Parent, Family, Teacher, Other, and also have a text box that the user
needs to fill in if 'other' is selected. I am trying to use javascript to
ensure that if the user selects something other than 'other', and fills in
the text box, that an error message appears. Any help would be greatly
appreciated.
<!--
function Validate(){
i=0
chosen = ""
var str = document.MTPSFY10.ServiceFormat_OtherDesc.value .replace(/\s/g,'');
for(i=0; i<document.MTPSFY10["ServiceFormat"].length; i++){
if(document.MTPSFY10["ServiceFormat"].selected){
chosen = chosen + document.MTPSFY10["ServiceFormat"].value
if(chosen !== "06" && str !== ""){
alert("Please Fill In Service Format Other Description");
document.MTPSFY10["ServiceFormat"].focus();
return false;}
}
}
return true
}
//-->
</script></head>
<body>
<form name="MTPSFY10" method="POST" onsubmit="return Validate();"
action="--WEBBOT-SELF--">
<table border="1" cellspacing="0" cellpadding="2" width="616">
<tr>
<td width="316"><select size="6" name="ServiceFormat" multiple>
<option value="01">Individual</option>
<option value="02">Group</option>
<option value="03">Parent</option>
<option value="04">Family</option>
<option value="05">Teacher</option>
<option value="06">Other</option>
</select></td>
<tr>
<td width="316">Other Description: <input type="text"
name="ServiceFormat_OtherDesc" size="20" maxlength=50></td>
</tr>
</table>
<p> </p>
<p><input type="submit" value="Submit" name="B1">
</p>
</form>
</body>
</html>