I'm not much of a Javascript guy so this was honestly a well thought out attempt at creating a function, but I seem to have hit a wall.
Basically I'm trying to create a generic 'select all' checkbox function. So if you check the master box, the function checks all of the sub boxes. That's not the problem though because that part works.
What doesn't work is when you uncheck the box, it doesn't uncheck the sub boxes.
Note that this does work if I check the state of the first sub box to determine if I should 'checkAll' or 'uncheckAll' so my error is in this function. For some reason unchecking 'nameOfBox'+'All' does not trigger the uncheckAll function, but checking it initially does trigger the checkAll function.
function toggleChecked(field){
with (document.form) {
for (var i=0; i < elements.length; i++) {
if (elements[i].type == 'checkbox' && elements[i].name == field+'All') {
if (elements[i].checked == true) {
checkAll(field);
}else{
uncheckAll(field);
}
break;
}
}
}
}
Like I said, I'm not really a Javascript guy so I'm sure it's something dumb that I'm just not familiar with. Also, any suggestions on my technique are welcome as well but I don't want to get into jQuery just yet. (One project at a time) This was adapted from something that worked in another case so it's truly makeshift.