I have the following HTML scenario:
<div>
<input id="txt0" type="text" /><input type="checkbox" id="chk0" /></div>
<div>
<input id="txt1" type="text" /><input type="checkbox" id="chk1" /></div>
<!-- etc -->
<div>
<input id="txtN" type="text" /><input type="checkbox" id="chkN" /></div>
If checkbox N is checked, then textbox N is a mandatory field.
I've just started to work with a (the?) jQuery validation module and am trying to figure out how to achieve this validation, which seems just that bit more complex than the examples.
Conceptually I think I want to add a CSS class to my checkboxes, then use addClassRules
to add a custom rule. However, the challenge is how to specify the relevant textbox for each checkbox.
My HTML is generated using ASP.NET MVC, so I could dynamically generate the JavaScript that would specify a rule for each checkbox, but this seems a bit long-winded.