jquery get all checked checkboxes 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: get value of all checked boxes jquery
var values = $('input[name=grepperRocks]:checked')
.map(() => { return this.value }).get();
Example 3: jquery get all checkbox checked
$('.theClass:checkbox:checked')
Example 4: select all checkboxes jquery
$('input:checkbox').prop('checked', true);
Example 5: jquery get selected checkboxes
var selected = [];
$('#checkboxes input:checked').each(function() {
selected.push($(this).attr('name'));
});
Example 6: select all checkbox jquery
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form>
<table>
<tr>
<td><input type="checkbox" id="select_all" /></td>
</tr>
<tr>
<td><input type="checkbox" name="select[]" /></td>
</tr>
<tr>
<td><input type="checkbox" name="select[]" /></td>
</tr>
<tr>
<td><input type="checkbox" name="select[]" /></td>
</tr>
</table>
</form>