> I have a form containing two radio buttons and under each button are
some
> related checkboxes. What I want to do is disable the checkboxes under
the
> unchecked radio button.
>
> Does anyone have a code snippet of some javascript that would do this.
I
> can't seem to find anything at javascriptsource.com.
This is all just chopped and pasted... hopefully it's about right.
Put this in all of your radio buttons.
onClick="clickRadio(this.name);
and give them each the same name="" but a unique value="". Give the form
and each of the checkboxes unique names too. Then, write this function
in the <head>:
function clickRadio(radioName); {
// Loop through the radio button array to work out which one is
selected.
for (var i = 0; i < document.formName.radioName.length; i++) {
if (document.formName.radioName[i].checked) {
var radioValue = document.formName.radioName[i].value;
}
}
// If they picked "value1",
if (radioValue == "value1") {
// enable the checkboxes beneath it and disable those under
radio2.
document.formName.checkbox1Name.disabled = false;
document.formName.checkbox2Name.disabled = false;
document.formName.checkbox3Name.disabled = true;
document.formName.checkbox4Name.disabled = true;
// Otherwise, if it's "value2",
} else if (radioValue == "value2") {
// do the opposite.
document.formName.checkbox1Name.disabled = true;
document.formName.checkbox2Name.disabled = true;
document.formName.checkbox3Name.disabled = false;
document.formName.checkbox4Name.disabled = false;
}
}
}
Replacing formName with the name of the form and checkboxXName with the
name of each checkbox and value1 and value2 with the actual values
you've assigned to the two radio buttons.
--
Aidan Whitehall <[EMAIL PROTECTED]>
Macromedia ColdFusion Developer
Fairbanks Environmental Ltd +44 (0)1695 51775
________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
--
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]