开发者

jQuery validation plugin question

I have a web form that is using this awesome p开发者_开发知识库lugin and I'm trying to set up a rule. In my form, I have a Quantity field. If the Quantity field is set to 1 AND a checkbox is checked, then I want to validate a field.

My form is setup like:

Quantity      TEXTBOX      id = txtQuantity
Gift?         CHECKBOX     id = #other
Recipient     TEXTBOX      id = txtRecipient

and my jQuery code is:

txtQuantity: "required",
txtRecipientEmail: { required: "#other:checked" },

I tried:

txtRecipientEmail: { required: "#other:checked", required: "$('txtQuantity').val() == '1'" }

but that's not working

Is there another way to do this?


required can take a function as well, which is what you want here:

txtRecipientEmail: { 
  required: function() { 
    return $("#other:checked").length && $("#txtQuantity").val() == '1'; 
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜