开发者

jQuery validate only if a specific radio button is selected

I got stuck at a particular situation

I have 2 radio buttons

<input type="radio" value="YES" id="sub" name="sub">Yes
<input type="radio" value="NO" id="s开发者_JAVA技巧ub" name="sub">No

When, Yes is selected, I need to validated 1 text-field

<input type="text" id="price" name="price" />

I am using jQuery validation plug-in

Please help me with this, Thanks.


You can set up dependency validation as seen here http://docs.jquery.com/Plugins/Validation/Methods/required#dependency-expression

$('#myForm').validate(rules: {
   price: { 
     required: '#sub[value="YES"]:checked'
    }
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜