Calling onclick on a radiobutton list using javascript

后端 未结 7 2100
灰色年华
灰色年华 2020-12-01 13:38

How do I call onclick on a radiobutton list using javascript?

相关标签:
7条回答
  • 2020-12-01 14:18

    Hi, I think all of the above might work. In case what you need is simple, I used:
    
    <body>
        <div class="radio-buttons-choice" id="container-3-radio-buttons-choice">
            <input type="radio" name="one" id="one-variable-equations" onclick="checkRadio(name)"><label>Only one</label><br>
            <input type="radio" name="multiple" id="multiple-variable-equations" onclick="checkRadio(name)"><label>I have multiple</label>
        </div>
    
    <script>
    function checkRadio(name) {
        if(name == "one"){
        console.log("Choice: ", name);
            document.getElementById("one-variable-equations").checked = true;
            document.getElementById("multiple-variable-equations").checked = false;
    
        } else if (name == "multiple"){
            console.log("Choice: ", name);
            document.getElementById("multiple-variable-equations").checked = true;
            document.getElementById("one-variable-equations").checked = false;
        }
    }
    </script>
    </body>

    0 讨论(0)
提交回复
热议问题