1

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;
        }

},
1
  • 1
    Please share your HTML or tell what type of control #type is. Like is it a textbox or else.
    – Anki
    Nov 29, 2018 at 5:07

3 Answers 3

1

Try below code.

nic: {
    isRequired: function(){
        var val = ('#type').val(); 
        if(val == 3 || val == 7){
          return false;
        }
        return true;
},

1

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

0

Try this:

required: function(element){
    if($('#type').val()==3){
        return false;
    }
    else if($('#type').val()==7){
        return false;
    }
    else{
        return true;
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.