1

I have a group of checkboxes that each have their own name, so they are not a checkbox group. I need a custom method for jQuery Validate that will make sure 1 or more is checked. Also, typically you tie a validation method to a field, but this covers lots of fields, so is therea jQuery Validate function that allows me to tie this to the submit so that it runs along with the other typical field required checks when the submit button is pressed?

Example checkboxes:

<form id="form" name="form>
<input type="checkbox" name="app1" value="y" />App 1
<input type="checkbox" name="app2" value="y" />App 2
<input type="checkbox" name="app3" value="y" />App 3
<input type="checkbox" name="app4" value="y" />App 4
<input type="submit" value="Submit">
</form>

1 Answer 1

2

You can just check to see if any of the forms children are checked.

if (!$('#form').children(':checked').length) return false;

Sign up to request clarification or add additional context in comments.

2 Comments

What ended up working was if (!$('#account_update').find('input:checked').length) return false; Thanks for putting me on the right track.
Your actual code is different than the example then, .children() will suffice for your example because it's only going down one DOM level, whereas find will check all DOM levels.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.