Computing.Net > Forums > Programming > Disabling Checkboxes woth JavaScrip

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.

Disabling Checkboxes woth JavaScrip

Reply to Message Icon

Name: chris_dee
Date: February 24, 2006 at 09:35:24 Pacific
OS: Windows XP sp2
CPU/Ram: AMD Athlon 1800xp 256mb R
Comment:

Hi

I am creating a webpage (using JavaScript) that must disable a set of check boxes when a specific radio button is selected.

Then, when another radio button is selected, it should then enable the set of checkboxes so that they can be used as part of the form.

I have tried to do it the same way as disabling a text field, but it doesn't have the same properties so it can't be treated in they same way.

Thanks




Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: February 24, 2006 at 11:09:35 Pacific
Reply:

I'm not sure how you are trying to disable checkboxes, but it works the same for me. Create an htm page with the code below and that should get you started:

<html>
<head>
<script language="javascript">
function setBoxes() {
if (document.myForm.rswitch[0].checked==true) {
document.myForm.box1.disabled = false;
document.myForm.box2.disabled = false;
document.myForm.box3.disabled = false;
} else {
document.myForm.box1.disabled = true;
document.myForm.box2.disabled = true;
document.myForm.box3.disabled = true;
}

}
</script>
</head>

<body>

<form name="myForm" action="">
<input type="radio" name="rswitch" value="Enabled" onclick="setBoxes();" checked>Enabled

<input type="radio" name="rswitch" value="Disabled" onclick="setBoxes();">Disabled



<input type="checkbox" name="box1" value="1">Box 1

<input type="checkbox" name="box2" value="2">Box 2

<input type="checkbox" name="box3" value="3">Box 3

</form>

</body>

</html>

And depending on your needs you may want to add code to uncheck the checkboxes when disabling them with:
document.myForm.box1.checked = false;

Michael J


0

Response Number 2
Name: chris_dee
Date: February 24, 2006 at 11:37:43 Pacific
Reply:

Hey, thanks for that, but i cant get that to work with what im tryin to do. i have named all of my checkboxes with the same name "equipment[]" so that when i submit it to my php page, it is in an array ($_POST['equipment']).


0

Response Number 3
Name: Michael J (by mjdamato)
Date: February 25, 2006 at 10:00:55 Pacific
Reply:

Well then, that would be your problem. There's no way I know of to make mutiple checkboxes treated as arrays on an HTML form.

You need to use differntly named checkboxes and then put the results into an array on the backend.

Michael J


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Disabling Checkboxes woth JavaScrip

HTML Checkbox Grey Out www.computing.net/answers/programming/html-checkbox-grey-out/4252.html

button enabled if checkbox checked www.computing.net/answers/programming/button-enabled-if-checkbox-checked/9693.html

Checkbox Name: Heeelp! www.computing.net/answers/programming/checkbox-name-heeelp/2264.html