The validation Of Budget Range is not working in the below code. It Brings Different Results at different point of time.
<table>
<tr>
<td>
Budget Range
</td>
<td>
<select id="start">
<option value="">---Select---</option>
<option value="0">0</option>
<option value="1000000">10 Lakhs</option>
<option value="2500000">25 Lakhs</option>
<option value="5000000">50 Lakhs</option>
<option value="7500000">75 Lakhs</option>
<option value="10000000">1 Crore</option>
<option value="12500000">1 Crore 25 Lakhs</option>
<option value="15000000">1 Crore 50 Lakhs</option>
<option value="17500000">1 Crore 75 Lakhs</option>
<option value="20000000">2 Crore</option>
<option value="25000000">2 Crore 50 Lakhs</option>
<option value="30000000">3 Crore</option>
<option value="35000000">3 Crore 50 Lakhs</option>
<option value="40000000">4 Crore</option>
<option value="45000000">4 Crore 50 Lakhs</option>
</select>
to
<select id="end" onchange="selectRange()">
<option value="0">---Select---</option>
<option value="1000000">10 Lakhs</option>
<option value="2500000">25 Lakhs</option>
<option value="5000000">50 Lakhs</option>
<option value="7500000">75 Lakhs</option>
<option value="10000000">1 Crore</option>
<option value="12500000">1 Crore 25 Lakhs</option>
<option value="15000000">1 Crore 50 Lakhs</option>
<option value="17500000">1 Crore 75 Lakhs</option>
<option value="20000000">2 Crore</option>
<option value="25000000">2 Crore 50 Lakhs</option>
<option value="30000000">3 Crore</option>
<option value="35000000">3 Crore 50 Lakhs</option>
<option value="40000000">4 Crore</option>
<option value="45000000">4 Crore 50 Lakhs</option>
</select>
</td>
</tr>
</table>
<script>
function selectRange() {
$startRange = document.getElementById('start').value;
$endRange = document.getElementById('end').value;
alert($startRange);
alert($endRange);
alert($startRange > $endRange);
if ($startRange > $endRange) {
alert('The Budget End Should be Greater than Budget Start');
$endRange = document.getElementById('end').value = 0;
return false
}
}
</script>
The validation Of Budget Range is not working in the above code. It Brings Different Results at different point of time.
when you are getting value these are coming as string or your comparison is based on string value, so it is producing wrong result. cast them to number will help.
just replace these line of code
to
or
and check this jsfiddle http://jsfiddle.net/QWLEW/2/ using parseInt function
or check this http://jsfiddle.net/QWLEW/3/ using Number function