My goal is to perform arithmetic operations based on the selected radio button value.
<html>
<body>
<br>Please enter the first number:
<input type="text" id="txt1" name="text1">Enter the second number:
<input type="text" id="txt2" name="text2">
<form>
<input type="radio" name="oper" value="1" checked>Add
<br>
<input type="radio" name="oper" value="2">Multiply
<br>
<input type="radio" name="oper" value="3">Subtract
</form>
<p id="demo"></p>
<script>
function myFunction() {
var y = document.getElementById("txt1").value;
var z = document.getElementById("txt2").value;
var o = getCheckedRadioValue("oper");
if(+o == 1)
var x = +y + +z;
if(+o == 2)
var x = +y * +z;
if(+o == 3)
var x = +y - +z;
document.getElementById("demo").innerHTML = x;
</script>
<button onclick="myFunction()">Calculate</button>
<br/>
</body>
</html>