Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q761 How can I compare two selected items from two different select form fields?

You are here: irt.org | FAQ | JavaScript | Form | 6 | Q761 [ previous next ]

Try:

<SCRIPT LANGUAGE="JavaScript"><!--
function test(what) {
    if (what.select1.options[what.select1.selectedIndex].value == what.select2.options[what.select2.selectedIndex].value)
        alert('They are the same');
}
--></SCRIPT>

<FORM NAME="myForm">

<SELECT NAME="select1">
<OPTION VALUE="abc">123
<OPTION VALUE="def">456
<OPTION VALUE="ghi">789
</SELECT>


<SELECT NAME="select2">
<OPTION VALUE="abc">123
<OPTION VALUE="def">456
<OPTION VALUE="ghi">789
</SELECT>

<INPUT TYPE="BUTTON" VALUE="SUBMIT" onClick="test(this.form)">

</FORM>

©2018 Martin Webb