I have one dropdown menu named as dlUserRole
. Inside of it, there are 2 values with index 0
and 1
.
I am trying to apply rules for the field ddlSupervisor
, like a validation such that if selected index of ddlUserRole
is 0 there should be no selection or rule in ddlSupervisor
, otherwise there should be at-least 1 selection in ddlSupervisor
.
I have a working code for 2 values in ddluserRole
dropdown. Now, I added 3rd filed there and I want to apply the same rule, but on selection of 3rd field from ddluserRole
(and though I made a choice in ddlSupervisor
), I am getting error as
"Please select value between 0 and 1 "
... My half working jQuery code as follows:
$('#ddlUserRole').change(function () {
var selectedValue = document.getElementById('ddlUserRole');
if (selectedValue.selectedIndex == '1') {
$("#ddlSupervisor").rules('add', {
range: [1, @double.MaxValue],
messages: {
range: "Please Enter Supervisor"
}
});
}
else {
$("#ddlSupervisor").rules('add', {
range: [0, @double.MaxValue],
});
}
});
I changed the condition to
if (selectedValue.selectedIndex == '1' || selectedValue.selectedIndex == '2')
... but not worked yet. How should I make the above validation?