I am using mvc4
I have 2 dropdownlist one is minimum experience
and the oher is maximum experience
, i am trying to validate minimum with maximum vice-versa from client side, but not getting it worked in a way i want it. The things i want to achieve like..
1. Minimum should be always less than maximum.
2. if minimum and maximum both are 0
then it should go on.
3. both can allow blank (Don't want to give min value or max value), i mean that user can also select default values as it is like ---minimum---
and ---maximum---
.
4. if minimum is not selected just maximum is selected then it should go on. same case in minimum too.
So far i have this:
Created FIDDLE to illustrate idea.
jQuery
_ **_EDITED** _____________
Reached so close, Come up to this, now just one thing remaning, maximum
is checked as a value and compared, but i want to ignore it via condition.
$("#MinExperienceDropDown").change(function () {
if ((($(this).val()) != "" && ($("#MaxExperienceDropDown").val() != "")) && ($("#MaxExperienceDropDown").val() != "") && ($(this).val() > $("#MaxExperienceDropDown").val())) {
alert('Minimum expreience should be less than maximum');
}
});
$("#MaxExperienceDropDown").change(function () {
if ($(this).val() < $("#MinExperienceDropDown").val()) {
alert('Maximum expreience should be greater than minimum');
}
});
HTML
<div style="text-align: left">
<select name="MinExperience" id="MinExperienceDropDown" style="width: 32%" class="select">
<option value="">--Minimum--</option>
<option value="0">0</option>
<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="MaxExperience" id="MaxExperienceDropDown" style="width: 32%; float: right;margin-right: 82px" class="select">
<option value="">--Maximum--</option>
<option value="0">0</option>
<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>
</div>
Any help is greatly appreciated.
Thank you all in advance.