Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Selecting a radiobutton on selecting a value from dropdownlist

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 197
    Comment on it

    The code below helps to get a particular radio button checked on selecting a particular value from the dropdownlist.

    <form>
        <div>
            <select id="selectvalue" onchange="Checkbox();">
                <option value="1">Select 1</option>
                <option value="2">Select 2</option>
                <option value="3">Select 3</option>
            </select>
            <input name="test" id="check1" value="1" type="radio">
            <input name="test" id="check2" value="2" type="radio">
            <input name="test" id="check3" value="3" type="radio">
        </div>
     </form>
    
    <script type="text/javascript">
    
     function Checkbox() {
              // parseInt() is used to change the string into int.  
               var id = parseInt(document.getElementById('selectvalue').value);
    
                switch (id) {
                    case 1:
                        document.getElementById("check1").checked = "checked";
                        break;
                    case 2:
                        document.getElementById("check2").checked = "checked";
                        break;
                    case 3:
                        document.getElementById("check3").checked = "checked";
                        break;
                }
    }
    </script>
    

    Below is the generated output from the above code:

    <script type="text/javascript"> function Checkbox() { // parseInt() is used to change the string into int. var id = parseInt(document.getElementById('selectvalue').value); switch (id) { case 1: document.getElementById("check1").checked = "checked"; break; case 2: document.getElementById("check2").checked = "checked"; break; case 3: document.getElementById("check3").checked = "checked"; break; } } </script>

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: