jquery validate all checkbox checked code example
Example 1: jquery validate all checkbox checked
<form id="form1" action="/controller/action" method="post">
<input type="checkbox" name="box1" class="cBox" />
<input type="checkbox" name="box2" class="cBox" />
<input type="checkbox" name="box3" class="cBox" />
<input type="submit" value="Submit" />
</form>
<script>
$('#form1').submit(function() {
if ($('input:checkbox', this).length == $('input:checked', this).length ) {
} else {
alert('Please tick all checkboxes!');
return false;
}
});
</script>
Example 2: jquery get all checkbox checked
$('.theClass:checkbox:checked')
Example 3: jquery check if all checkbox is not checked
$('#checkAll').click(function () {
$('input:checkbox').prop('checked', this.checked);
});