I have a form with a list of checkboxs. I want to create a checkAll and UncheckAll boxes for better user experience. I tried a lot of code that I got from Internet, but none
var form = document.getElementById('groupImportForm');
var inputs = form.elements;
var checkboxes = [];
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == 'checkbox') {
inputs[i].checked =true;
}
}
Javascript version of the example
Same thin using jQuery
$(".uncheckAll']").click(function() {
$('.inputs').attr('checked','checked'); //add the atrribute checked
// $('.inputs').removeAttr("checked"); //remove the attribute checked
});
Working example of jQuery