Answers for "radio button js"

3

javascript radio button value if checked

//alert(document.querySelector('input[name = "comp"]:checked').value);

$test=document.querySelector('input[name = "comp"]:checked').value;

if($test="silver") {
        amount=50;
    }else if($test="gold") {
      amount=90;
    }else{
      amount=30;
    }
Posted by: Guest on November-11-2020
2

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

Code answers related to "Javascript"

Browse Popular Code Answers by Language