// requests
const requests = {
'cont': document.querySelector(".requests"),
'main': document.querySelector("#requests_checkbox-main"),
'common': document.querySelectorAll("#requests_checkbox"),
'chk_num': 0,
'sum': 0
}
function active_main() {
for(let i=0; i<requests['common'].length;i++) {
requests['common'][i].addEventListener('change', () => {
if(this.checked == true &&this.length == requests['chk_num']) {
requests['main'].checked = true;
}
requests['chk_num']++;
console.log(requests['chk_num']);
});
}
}
function check_on(object) {
var listener = function (event) {
if(this.id == "requests_checkbox") {
requests['main'].checked = false;
}
}
for(let i=0; i<requests['common'].length;i++) {
requests['common'][i].checked = true;
requests['common'][i].addEventListener('change', listener, false);
}
}
function check_off(object) {
requests['chk_num'] = 0;
for(let i=0; i<requests['common'].length;i++) {
requests['common'][i].checked = false;
}
}
var checkbox = document.querySelector("input[type=checkbox]");
checkbox.addEventListener('change', function() {
// requests
active_main();
if (this.checked && this.id == "requests_checkbox-main") {
check_on(requests);
}
else if(this.checked == false && this.id == "requests_checkbox-main"){
check_off(requests);
}
});