Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enable-Diable Radio Buttons

 
Anand Jayaraman
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...


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???



Cheers
 
Anand Jayaraman
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:

<script>
function toggle(bool) {
document.getElementById("targetRadio1").disabled = bool;
document.getElementById("targetRadio2").disabled = bool;
}
</script>

<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
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)


Cheers
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic