Reputation: 25
In my form, one of my field is dependent on the value of another field like if it is required or not. I wrote below code but it is not working properly. Please help.
nic: {
required: function(element){
if(('#type').val()==3){
return false;
}
else if(('#type').val()==7){
return false;
}
else{
return true;
}
},
Upvotes: 1
Views: 65
Reputation: 343
some times condition might not correct check the value passed to condition. I mean is it 3 or 7 passed to condition
you can check it by
console.log($('#type').val()); to your condition
Upvotes: 1
Reputation: 417
Try below code.
nic: {
isRequired: function(){
var val = ('#type').val();
if(val == 3 || val == 7){
return false;
}
return true;
},
Upvotes: 1
Reputation: 360
Try this:
required: function(element){
if($('#type').val()==3){
return false;
}
else if($('#type').val()==7){
return false;
}
else{
return true;
}
}
Upvotes: 0