JavaScript program to print given number of radio buttons:
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Write a code to print numbers of radio buttons in JavaScript</title>
</head>
<body>
<span id="output"></span> <br><br>
<label for="num1"><input type="radio" name="numbers" onclick="radioBtnClick(this)" id="num1" value="5">5</label>
<label for="num2"><input type="radio" name="numbers" onclick="radioBtnClick(this)" id="num2" value="10">10</label>
<label for="num3"><input type="radio" name="numbers" onclick="radioBtnClick(this)" id="num3" value="15">15</label>
<label for="num4"><input type="radio" name="numbers" onclick="radioBtnClick(this)" id="num4" value="20">20</label>
<script>
function radioBtnClick(ob){
var num = ob.value;
document.getElementById("output").innerHTML = 'The selected number is '+num;
}
</script>
</body>
</html>
Output:
Comments
Post a Comment