Comparing two select elements values
Posted
by
user1135192
on Stack Overflow
See other posts from Stack Overflow
or by user1135192
Published on 2012-03-24T23:19:05Z
Indexed on
2012/03/24
23:29 UTC
Read the original article
Hit count: 187
JavaScript
|html
I've been been trying to look for a piece of javascript code that compares the values selected by a user in a html form from two <select>
tags. So if the user selects a minimum value that is greater than the maximum number an alert box in javascript should be displayed.
For example, if the user selects 5 bedrooms from the the MINIMUM bedrooms dropdown list and then 3 bedrooms from the MAXIMUM bedrooms dropdown list, this should not allow the form to be processed when the submit button is clicked. But is fine when 3 is selected from the MINIMUM dropdown list and 5 from the MAXIMUM dropdown list.
<form name="search" action="page3.php" method="GET">
<select name="minimumBeds">
<option value="1"> 1 </option>
<option value="2"> 2 </option>
<option value="3"> 3 </option>
<option value="4"> 4 </option>
<option value="5"> 5 </option>
</select>
<select name="maximumBeds">
<option value="1"> 1 </option>
<option value="2"> 2 </option>
<option value="3"> 3 </option>
<option value="4"> 4 </option>
<option value="5"> 5 </option>
</select>
</form>
© Stack Overflow or respective owner