Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I need to have 4 checkboxes (C1 C2 C3 C4) in a form, upon the page loading I would like C1 C2 C3 to be hidden and only visible if someone puts a tick in C4
I know that this is possible using Java script however supprising enough I can't seem to find a very good example on google.Can someone let me know a link to a good site with examples of doing this. Or if its not too much provide me with a quick sample code. Thanks so much for anyones help.

First of all, Java !== Javascript :D
Ok, above the </head>:[script language="JavaScript" type="text/JavaScript"]
function showAll() {
document.getElementById('C1').disabled = 0;
document.getElementById('C2').disabled = 0;
document.getElementById('C3').disabled = 0;
}
[/script]
and the checkboxes:[input id="C1" type="checkbox" disabled="true" /]
[input id="C2" type="checkbox" disabled="true" /]
[input id="C3" type="checkbox" disabled="true" /]
[input onclick="showAll();" type="checkbox" /]
If you prefer "show & hide", replace disabled in the field with style="visibility: hidden;" and use document.getElementById('').style.visibility = 'visible'; in the head script.If anyone has a better / more efficient way, please. I don't have much experience in javascript.

Your script is fine. However, since the optional three chaeckboxes should only be shown after C4 is checked I would assume that they should also be unchecked and hidden(disabled) when C4 is unchecked. So I would revise your script like this:
[script language="JavaScript" type="text/JavaScript"]
function showAll(field) {
if (field.checked) {
state = false;
} else {
state = true;
document.getElementById('C1').checked = false;
document.getElementById('C2').checked = false;
document.getElementById('C3').checked = false;
}
document.getElementById('C1').disabled = state;
document.getElementById('C2').disabled = state;
document.getElementById('C3').disabled = state;
}
[/script]And the checkboxes;
[input id="C1" name="C1" type="checkbox" disabled="true" /]
[input id="C2" name="C2" type="checkbox" disabled="true" /]
[input id="C3" name="C3" type="checkbox" disabled="true" /]
[input id="C4" name="C4" type="checkbox" onclick="showAll(this);" /]Michael J

Hey cheers for that, it looks exactly as I need, I will try tonight, thanks heaps. Hope this also helps someone else who has same question :)

![]() |
round corners ??!??
|
ActiveX not loading on ce...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |