jQuery: How to make a field required if two specific options are selected
Validating a form w/ jQuery. For simplicity, user selects from three options: "A_or_B", "C", or "D" from a drop down list. If A_or_B is chosen then the "Name" field is required. If C or D, then it isn't. This was done like so:
$("#form").validate({
rules: {
Name: {required: "#Letter[value=A_or_B]"}
}
});
Now I am required to make "A_or_B" 开发者_JAVA百科into two seperate entries, where either choice still makes the "Name" field required. How would I change the validation line for the Name field now that A and B are seperate entries on the drop down list?
Not sure if this will work but it might be worth a try.
$("#form").validate({
rules: {
Name: {required: "#Letter[value='A'], #Letter[value='B']"}
}
});
精彩评论