Require Field if certain radio buttons are checked in jQuery Validation Plugin
I have a form with 3 radio buttons:
<input id="Desktop" name="Usage" type="radio" value="Desktop" /> Desktop <input id="Laptop" name="Usage" type="radio" value="Laptop" /> Laptop <input id="iPad" name="Usage" type="radio" value="iPad" /> iPad
If one of the first two radio buttons are checked then I dynamically ask the user if they are using a PC or a MAC, which is a set of radio’s called MacOrPC. I want the PC/MAC question to be required only if the Desktop or Laptop radio buttons are checked. To do this, I think I figured out the syntax in the jQuery Validation Plugin. Here’s the rule syntax I used that seems to work using the ampersand:
rules: {
MacOrPC: {required: "#Desktop:checked" & "#Laptop:checked"}
}
Thank you for this. I have been trying to find a way to do this for a few hours now and your way is so simple. Worked like a charm.