I have the site with 9 checkboxes, each associated with a div. When a checkbox is selected, the div related to it is shown. When another checkbox is selected, the div related to that other is also shown. For example, chkCamp1 shows optCamp1. chkCamp2 shows optCamp2 and "some" with optCamp1, since chkCamp1 is deselected.
I just can not get the div from the unselected checkbox to "pop up."
HTML with nine checkboxes:
<input id="chkCamp1" type="checkbox" class="cb" style="margin-left: -25px" onclick="showMe('optCamp1', this)">
<input id="chkCamp2" type="checkbox" class="cb" style="margin-left: -25px" onclick="showMe('optCamp2', this)">
<input id="chkCamp3" type="checkbox" class="cb" style="margin-left: -25px" onclick="showMe('optCamp3', this)">
<input id="chkCamp4" type="checkbox" class="cb" style="margin-left: -25px" onclick="showMe('optCamp4', this)">
<input id="chkCamp5" type="checkbox" class="cb" style="margin-left: -25px" onclick="showMe('optCamp5', this)">
<input id="chkCamp6" type="checkbox" class="cb" style="margin-left: -25px" onclick="showMe('optCamp6', this)">
<input id="chkCamp7" type="checkbox" class="cb" style="margin-left: -25px" onclick="showMe('optCamp7', this)">
<input id="chkCamp8" type="checkbox" class="cb" style="margin-left: -25px" onclick="showMe('optCamp8', this)">
<input id="chkCamp9" type="checkbox" class="cb" style="margin-left: -25px" onclick="showMe('optCamp9', this)">
And the showMe function as it is currently.
function showMe(it, elem){
var elems = document.getElementsByClassName("cb");
var currentState = elem.checked;
var elemsLength = elems.length;
for(i=0; i<elemsLength; i++){
if(elems[i].type === "checkbox"){
elems[i].checked = false;
}
}
elem.checked = currentState;
if(elem.checked = true){
document.getElementById(it).style.display = 'block';
}
else{
document.getElementById(it).style.display = 'none';
}
}
How can I improve this?