1
I own the site with 9 checkboxes, each associated with a div. When a checkbox is selected, the related div is shown. When another checkbox is selected, the div related to that other one is also shown. For example, chkCamp1 shows optCamp1. chkCamp2 shows optCamp2 and "some" with optCamp1, since chkCamp1 is deselected.
I just can’t get the div from the deselected checkbox to "disappear" from the screen.
HTML with the 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 at the moment.
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 make it better?
It worked, thank you!!!
– Gustavo Hoppe Levin
In the above example, div does not disappear when the checkbox selection is undone.
– Tobias Mesquita
@Tobymosque fault mine, I had not attacked me to this situation. I already altered to meet.
– Randrade
now it’s 100%, +1
– Tobias Mesquita