Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2008
    Thanked 0 Times in 0 Posts

    Show and hidden radio button depending on Dropdown selection

    Dear Javascript programmers,

    Do you have an example of a Javascript something like this:

    A dropdownlist with values "one" and "two". The radio button is not visible (as a start).
    - If you have selected "one" from the dropdown list, then a radio button will appear.
    - If you have selected "two" from the dropdown list, then a radio button will NOT appear.


    Gouda - The Netherlands

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,564 Times in 2,542 Posts
    In IE you may not have a single radio button in a group - if there is only one choice use a checkbox instead.

    <form name = "myform">
    <select name = "mySelect" onchange = "showRadioButtons()">
    <option value = "0">Select ......</option>
    <option value = "1">One</option>
    <option value = "2">Two</option>
    <div id = "rads" style="display:none">
    Check a radio button 1<input type = "radio" name = "rad1">2<input type = "radio" name = "rad1">
    <script type = "text/javascript">
    function showRadioButtons() {
    document.getElementById("rads").style.display="none"; // hide the radios
    var val = document.myform.mySelect.value;  
    if (val == 1) {
    document.getElementById("rads").style.display="block";  // show the radios if One selected
    var r = document.myform.rad1;
    for (var i =0; i<r.length; i++) {  // uncheck the radio previously selected
    r[i].checked = false;

    "I'm such a good lover because I practice a lot on my own." - Woody Allen
    Last edited by Philip M; 01-10-2012 at 10:09 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts