Hi,
I have a form with two drop down lists, and I kile two validate them against each other.
The basic concept is:
- the to lists are required, so they must have a value;
- the two list must not have the same value;
- if any of the lists have a proper value selected, a text box may appear, which is mandatory as well.
I'm not a js guru myself; I googled and modified the following code to myself:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function validateForm(objForm)
{
if (document.testform.Make.op
tions[docu
ment.testf
orm.Make.o
ptions.sel
ectedIndex
].value == "0")
alert("You must choose an option");
if (document.testform.Make2.o
ptions[doc
ument.test
form.Make2
.options.s
electedInd
ex].value == "0")
alert("You must choose an option2");
if (document.testform.Make.op
tions[docu
ment.testf
orm.Make.o
ptions.sel
ectedIndex
].value == document.testform.Make2.op
tions[docu
ment.testf
orm.Make2.
options.se
lectedInde
x].value)
alert("omg");
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<FORM ACTION="#" NAME="testform">
<p>
<SELECT NAME="Make">
<OPTION VALUE="0" SELECTED>Select One</OPTION>
<OPTION VALUE="1">Ford</OPTION>
<OPTION VALUE="2">Chevy</OPTION>
<OPTION VALUE="3">Pontiac</OPTION>
<OPTION VALUE="4">Dodge</OPTION>
</SELECT>
<SELECT NAME="Make2">
<OPTION VALUE="0" SELECTED>Select One</OPTION>
<OPTION VALUE="1">Ford</OPTION>
<OPTION VALUE="2">Chevy</OPTION>
<OPTION VALUE="3">Pontiac</OPTION>
<OPTION VALUE="4">Dodge</OPTION>
</SELECT>
</p>
<p>
<input type="text" name="Details" id="Details" style="display:none;">
</p>
<p>
<INPUT TYPE="BUTTON" VALUE="Send form"
onClick="validateForm(docu
ment.testf
orm)">
</p>
</FORM>
</BODY>
</HTML>
I hope it helps & thanks for your help indeed!
thurston
ps: at the moment I have only 395 points left, but I will raise the bar later
Start Free Trial