File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Enable-Diable Radio Buttons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Enable-Diable Radio Buttons" Watch "Enable-Diable Radio Buttons" New topic

Enable-Diable Radio Buttons

Anand Jayaraman
Ranch Hand

Joined: Jan 28, 2004
Posts: 104

I have been having this problem for a while. I have two radio buttons and when the user clicks on the first one, two new radio buttons must be enabled for the user to use (by default, the last set of radio buttons are diabled).

For example:

In the above code, A11 and A22 are disabled by default. When the user selects the first radio button, i.e, A, I want to enable radio buttons, A11 and A22.

I wanted dynamic radio buttons, but have now settled for this. Can someone help me with this???

Anand Jayaraman
Ranch Hand

Joined: Jan 28, 2004
Posts: 104

I tried something like this, but there is a problem with this.

However, what this does is, it enables the first radio button (i.e A11) and DOES NOT ENABLE THE OTHER ONE...

Any fix???
Pedro Penna
Ranch Hand

Joined: Jun 05, 2004
Posts: 46
Try this:

function toggle(bool) {
document.getElementById("targetRadio1").disabled = bool;
document.getElementById("targetRadio2").disabled = bool;

<input type="radio" name="r1" on click="toggle(true)" value="1" />
<input type="radio" name="r1" on click="toggle(false)" value="2" />
<br />
<input type="radio" name="r2" value="3" id="targetRadio1" disabled />
<input type="radio" name="r2" value="4" id="targetRadio2" disabled />

All you have to do now is remove the internal space in the event handlers "on click". JavaRanch just won't let me include a post including this word... Aparently there's some evil conspiracy theory involving JavaScript or something like that...

If you want dinamically generated radio buttons, all you have to add is a loop statement to build the "id" attribute, like "targetRadio" + x
Anand Jayaraman
Ranch Hand

Joined: Jan 28, 2004
Posts: 104
Right On!

Thanks for that! People have always wondered why Aussies spell words differently. I'd attribute my spelling to Javaranch.. (If you noticed my onKlick in the code above)

I agree. Here's the link:
subject: Enable-Diable Radio Buttons
It's not a secret anymore!