document.querySelector("#checkAll").addEventListener("change", changeGroups);
$('input[name="groupItem"]').on('change', function () {
selectAllGroups()
})
function changeGroups() {
var $this = $(this);
var checked = $this.prop('checked');
$('input[name="groupItem"]').prop('checked', checked);
}
function selectAllGroups() {
var boxLength = $('input[name="groupItem"]').length;
var checkedLength = $('input[name="groupItem"]:checked').length;
var selectAll = (boxLength == checkedLength);
$('#checkAll').prop('checked', selectAll);
}