PDA

View Full Version : Checkboxes



kermit_cof
09-14-2005, 02:55 PM
Hi

Checkboxes:

I need a script that shows a layer when the checkbox is checked and hides a layer when the checkbox is unchecked.

I've tried Dreamweaver's behavior functions but to no avail.

Pls help!

Thanks

jscheuer1
09-16-2005, 04:18 AM
<input type="checkbox" onclick="if (this.checked) {document.getElementById('id1').style.visibility='visible'} else {document.getElementById('id1').style.visibility='hidden'};" />
<div id="id1" style="visibility:hidden">Hi</div>

kermit_cof
09-19-2005, 10:04 AM
It works like a dream!

Thanks Jon

mwinter
09-19-2005, 11:12 AM
<input type="checkbox" onclick="if (this.checked) {document.getElementById('id1').style.visibility='visible'} else {document.getElementById('id1').style.visibility='hidden'};" />
<div id="id1" style="visibility:hidden">Hi</div>You could simplify that slightly using the conditional operator:


document.getElementById('id1').style.visibility = this.checked ? 'visible' : 'hidden';However, I'd use something more robust:


function setVisibility(object, visibility) {
if(('string' == typeof object) && document.getElementById) {
object = document.getElementById(object);
}
if(object && object.style) {
object.style.visibility = visibility;
}
}

setVisibility('id1', this.checked ? 'visible' : 'hidden');Mike