$('#form').submit(function(e) {
var errorElements = [], valid = false;
$('.checkboxgroup', this).each(function() {
var checkBoxes = $(':checkbox', this), oneChecked = false;
checkBoxes.each(function() {
if (!oneChecked && !$(this).is(':checked')) {
valid = false;
errorElements.push(this);
} else {
oneChecked = true;
}
});
});
e.preventDefault(); // cancels form submit.. remove if you dont need.
if (errorElements.length) {
// code to do what you want if it fails
} else {
// code to do what you want if it passes
}
});
html:
<div class="checkboxgroup">
(checkbox html)
</div>
<div class="checkboxgroup">
(checkbox html)
</div>