Answers for "js input radio"

8

html radio button checked

<input type="radio" id="huey" name="drone" value="huey"
         checked> 
<!-- https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio-->
Posted by: Guest on May-17-2020
3

radio button html js

getElementById("radio_button").checked(); //returns boolean
Posted by: Guest on May-16-2021
0

radio button js

<!DOCTYPE html>
<html>
<head>
    <title>JavaScript Radio Buttons</title>
</head>
<body>
    <form>
        <input type="radio" name="choice" value="yes" id="choice-yes"> 
        <label for="choice-yes">Yes</label>
        <input type="radio" name="choice" value="no" id="choice-no">
        <label for="choice-no">No</label>
        <button id="btn">Show Selected Value</button>
    </form>
    <script>
        const btn = document.querySelector('#btn');
        // handle button click
        btn.onclick = function () {
            const rbs = document.querySelectorAll('input[name="choice"]');
            let selectedValue;
            for (const rb of rbs) {
                if (rb.checked) {
                    selectedValue = rb.value;
                    break;
                }
            }
            alert(selectedValue);
        };
    </script>
</body>
</html>Code language: HTML, XML (xml)
Posted by: Guest on September-29-2021
2

radio input value

<input type="radio" name="test" id="test" value="this is the value">
Posted by: Guest on October-30-2020

Browse Popular Code Answers by Language