PORGRAM IN JAVASCRIPT FOR CALCULATOR TYPE-4(WITH DIV ID FOR PRINTING)

<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.getElementById("xxx").innerHTML=("ADDITION OF TWO NUMBERS="+(f+s));

}

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

       document.getElementById("xxx").innerHTML=("SUBTRACTION OF TWO NUMBERS="+(f-s));

}

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

        document.getElementById("xxx").innerHTML=("PRODUCT OF TWO NUMBERS="+(f*s));

}

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

        document.getElementById("xxx").innerHTML=("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>

<div id="xxx"></div>

</form>

</body>

</html>

OUTPUT:



No comments:

Post a Comment