Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

JS - show if checkbox is checked

Oct 8, 2008 4:06AM PDT

Hello, I would like to show or hide a div if a checkbox is on or off.
I found the some code that worked perfectly in FF but in IE it makes all the content of the page disappear but the checkbox.

Here is the code im using, inside the head tag...
<script>
<!--
function c(){}
function test(){
if(document["form"]["box"].checked){
document.getElementById("myText").style.visibility="visible"}
else{
document.getElementById("myText").style.visibility="hidden"}
}
//-->
</script>


and here is the rest of the code...

<form name="form">

<label for="condiciones"><a href="#">Condiciones</a>
<input type="checkbox" name="box" checked="checked"
onclick ="c();test()" /></label>

</form>

<div id="myText"><img src="img.png" /></a></div>

I would love some help with this, I also tried similar ones with the same result.

Thanks a lot, Marcelo.

Discussion is locked