Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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

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']).

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

![]() |
![]() |
![]() |

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