PROGRAM FOR SIMPLE CALCULATOR TYPE-5(USING BUTTON FOR CHOICE)

 <html>

<head>

<script type = "text/javascript">

function add(){

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

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

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

}


function sub(){

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

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

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

}


function multiply(){

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

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

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

}


function divide(){

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

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

        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>

Select the operation to perform:<br>

<input type="button"  name="cal" onclick="add();" value="add" >

<input type="button"  name="cal" onclick="sub();" value="sub">

<input type="button"  name="cal" onclick="multiply();" value="mul">

<input type="button"  name="cal" onclick="divide();" value="div">

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

</form>

</body>

</html>

OUTPUT:



No comments:

Post a Comment