You have some issues in your function: Try this way:
Js
function CheckAllClick(elem) {
$(elem).closest('fieldset').find(':checkbox').prop('checked', elem.checked);
}
Markup
<input type="checkbox" ID="checkall1" onclick="CheckAllClick(this);">Check all</div>
Pass the element in the onclick function as this
and access it in your code.
If you can go with jquery approach then:
Add a class to your checkall check boxes
<input type="checkbox" class="checkAll" ID="checkall1" >Check all
With the same code, if you want to make the label click to check the checkbox then just wrap them in label
tag, same thing you can do with all the checkboxes by wrapping them in label which generally is a standard way:
<label><input type="checkbox" class="checkAll" ID="checkall1" >Check all<label>
Bind an event handler to a class
$('.checkAll').on('change', function(){
$(this).closest('fieldset').find(':checkbox').prop('checked', this.checked);
})
solved Group checkboxes in JSFiddle : Part 1 [closed]