Forum Moderators: open

Message Too Old, No Replies

Javascript + DOM

a message appears right underneath the checkbox

         

luckydude

4:42 pm on Jan 28, 2004 (gmt 0)

10+ Year Member



hey all, I am trying to create a javascript code where a message appears right underneath the "checkbox" after checking the checkbox. I don't want to make it an 'alert' box. It has to be a message that will appear after checking the box and goes away when it is 'unchecked'. Here is my checkbox:

<form>
<input type="checkbox" name="C_Box" id="CBox1"> Click here if you are a new user!
</form>

If anyone can give me some ideas, I would really appreciate it. Thanks in advance....

luckydude

BlobFisk

5:00 pm on Jan 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi luckydude,

You need to toggle the visibility of a layer on and off with an onClick event. To do this you need to use a variable to flag whether the visibility is on or off:


<script type="text/javascript">
counter = 0;

function show(layer) {

if(counter==0) {
document.getElementById(layer).style.visibility='visible';
counter=1;
}
else if(counter==1) {
document.getElementById(layer).style.visibility='hidden';
counter=0;
}
}
</script>

And in your HTML:


<input type="checkbox" onclick="show('layer1');">
<div id="layer1">
Hi There!
</div>

HTH

luckydude

3:52 am on Jan 29, 2004 (gmt 0)

10+ Year Member



Thanks BlobFisk for your help. I appreciate it.

luckydude