• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Enable-Diable Radio Buttons

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic