PROGRAM FOR SIMPLE CALCULATOR IN JAVASCRIPT-TYPE 3(USING RADIO BUTTON)

<html>

<head>

<script type = "text/javascript">

function calculator(){

var f=parseInt(document.getElementById("a").value);

var s=parseInt(document.getElementById("b").value);

if (document.getElementById("add").checked == true){

        document.writeln("ADDITION OF TWO NUMBERS="+(f+s));

}

if (document.getElementById("sub").checked == true){

        document.writeln("SUBTRACTION OF TWO NUMBERS="+(f-s));

}

if (document.getElementById("mul").checked == true){

        document.writeln("PRODUCT OF TWO NUMBERS="+(f*s));

}

if (document.getElementById("div").checked == true){

        document.writeln("DIVISION OF TWO NUMBERS="+(f/s));

}

}

</script>


</head>

<body>

<form name="calc">

ENTER FIRST NUMBER:<Input type="text" id="a" name="a"><br>

ENTER SECOND  NUMBER:<Input type="text" id="b" name="b"><br>

ENTER the operation to perform:<br>

<input type="radio" id="add" name="cal" value="add" >ADD<br>

<input type="radio" id="sub" name="cal" value="sub">SUBTRACT<br>

<input type="radio" id="mul" name="cal" value="mul">MULTIPLY<br>

<input type="radio" id="div" name="cal" value="div">DIVIDE<br>

<Input type="button" onclick="calculator();return false;" value="CLICK ME"><br>

</form>

</body>

</html>

OUTPUT:




No comments:

Post a Comment