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>
Chad Crowell
  • 601
  • 6
  • 16

1 Answers1

2

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

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

Robert
  • 21,110
  • 9
  • 55
  • 65
  • 1
    What ended up working was `if (!$('#account_update').find('input:checked').length) return false;` Thanks for putting me on the right track. – Chad Crowell Apr 22 '11 at 17:49
  • 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. – Robert Apr 22 '11 at 17:51