1//alert(document.querySelector('input[name = "comp"]:checked').value);
2
3$test=document.querySelector('input[name = "comp"]:checked').value;
4
5if($test="silver") {
6 amount=50;
7 }else if($test="gold") {
8 amount=90;
9 }else{
10 amount=30;
11 }
1<!DOCTYPE html>
2<html>
3<head>
4 <title>JavaScript Radio Buttons</title>
5</head>
6<body>
7 <form>
8 <input type="radio" name="choice" value="yes" id="choice-yes">
9 <label for="choice-yes">Yes</label>
10 <input type="radio" name="choice" value="no" id="choice-no">
11 <label for="choice-no">No</label>
12 <button id="btn">Show Selected Value</button>
13 </form>
14 <script>
15 const btn = document.querySelector('#btn');
16 // handle button click
17 btn.onclick = function () {
18 const rbs = document.querySelectorAll('input[name="choice"]');
19 let selectedValue;
20 for (const rb of rbs) {
21 if (rb.checked) {
22 selectedValue = rb.value;
23 break;
24 }
25 }
26 alert(selectedValue);
27 };
28 </script>
29</body>
30</html>Code language: HTML, XML (xml)