I have the following HTML edited to be shorter and more understandable:
<input type='checkbox' name='All' value='All' id='All' onclick='toggleAll(this)'/>
<label for='All'> Everyone</label>
<input type='checkbox' name='Resp' value='Resp' id='Resp' onclick='toggleResp(this)'/>
<label for='Resp'> Responsibles</label>
<input type='checkbox' name='9' value='9' id='9' onclick='toggleDept(this)' />
<label for='9'> Department 9</label>
<input type='checkbox' name='3-9-9' value='3-9-9' id='3-9-9' />
<label for='3-9-9'> Responsible Personnel 9</label>
<input type='checkbox' name='4-9-10' value='4-9-10' id='4-9-10' />
<label for='4-9-10'> General Personnel 10</label>
<input type='checkbox' name='4-9-11' value='4-9-11' id='4-9-11' />
<label for='4-9-11'> General Personnel 11</label>
In the name 4-9-10
, 4 stands for user type, if it's below 4 a user is responsible
. 9 stands for department ID and 10 stands for personnel ID.
When I click on the checkbox All
, all of the checkboxes are checked:
function toggleAll(source) {
inputs = document.getElementsByTagName("input");
for (var i in inputs) {
if(inputs[i].type == "checkbox") {
inputs[i].checked = source.checked;
}
}
}
When I click on the checkbox Resp
, all of the responsible personnels' checkboxes are checked:
function toggleResp(source) {
inputs = document.getElementsByTagName("input");
for (var i in inputs) {
if (inputs[i].type == "checkbox") {
if(parseInt(inputs[i].name.substring(0, inputs[i].name.indexOf("-"))) < 4)
inputs[i].checked = source.checked;
}
}
}
When I click on a department checkbox, department's personnels' checkboxes are checked:
function toggleDept(source) {
inputs = document.getElementsByTagName("input");
deptId = source.name;
for (var i in inputs) {
if (inputs[i].type == "checkbox") {
index = inputs[i].name.indexOf("-");
lastIndex = inputs[i].name.lastIndexOf("-");
iDeptId = inputs[i].name.substring(index + 1, lastIndex);
if (index != -1 && iDeptId == deptId.toString())
inputs[i].checked = source.checked;
}
}
}
I have 3 departments and varying number of personnel in those. Everything works great in Firefox, Chrome and Yandex. However, this only partially works in IE7. For example, when I press on All
, only department responsibles and departments are checked, a department isn't checked at all. Responsible
check and Department
works partially, too.
My question is: Is there a function or HTML element here in my codes which isn't compatible with earlier versions of IE7?