jquery validate all checkbox checked
var values=[];
$('input[name="your-checkbox-name[]"]:checked').each(function () {
values[values.length] = (this.checked ? $(this).val() : "");
});
4
2
<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 ) {
// everything's fine...
} else {
alert('Please tick all checkboxes!');
return false;
}
});
</script>
Thank you!
2
0
4.11
9
$('.theClass:checkbox:checked')
Thank you!
9
0
4.67
3
$('#checkAll').click(function () {
$('input:checkbox').prop('checked', this.checked);
});
Thank you!
3
0
Are there any code examples left?
New code examples in category Html