Computing.Net > Forums > Web Development > Java - Hiding checkboxes with Java

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Java - Hiding checkboxes with Java

Reply to Message Icon

Name: Skewkus
Date: June 20, 2006 at 05:33:05 Pacific
OS: XP
CPU/Ram: 2gig
Product: Athlon
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Laler
Date: June 20, 2006 at 06:37:33 Pacific
Reply:

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.

---
Site of the Day


0

Response Number 2
Name: Michael J (by mjdamato)
Date: June 20, 2006 at 07:13:21 Pacific
Reply:

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


0

Response Number 3
Name: Skewkus
Date: June 20, 2006 at 13:36:23 Pacific
Reply:

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 :)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


round corners ??!?? ActiveX not loading on ce...



Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Java - Hiding checkboxes with Java

Help with Checkboxes and array PHP www.computing.net/answers/webdevel/help-with-checkboxes-and-array-php/2568.html

Hide img if src invalid www.computing.net/answers/webdevel/hide-img-if-src-invalid/3422.html

PHP & checkboxes www.computing.net/answers/webdevel/php-amp-checkboxes/1122.html