CODE:
<html>
<head><title>ADDITION CALCULATOR</title>
<script language"javascript">
var num1;
var num2;
var sum;
function processVal1(){
    num1 = document.calc.num.value;
    num1 = parseInt(num1);
    if(isNaN(num1)){
       document.getElementById("labl").innerHTML="Enter A correct number";
       document.calc.num.value = null;
    }
    else{
       document.getElementById("plus").disabled = true;
       document.getElementById("equ").disabled = false;
       document.getElementById("labl").innerHTML=""+num1+"+";
       document.calc.num.value = null;
       document.getElementById("num").focus();
    }
 }
function addVal(){
     num2 = document.calc.num.value;
     num2 = parseInt(num2);
     if(isNaN(num2)){
        alert("Enter A correct number");
     }
     else{
      sum = num1 + num2;
      document.calc.num.value = sum;
      document.getElementById("equ").disabled = true;
      document.getElementById("plus").disabled = false;
     }  
}
function clearVal(){
     document.getElementById("equ").disabled = false;
     document.getElementById("plus").disabled = false;
     document.getElementById("labl").innerHTML="&nbsp;";
     document.calc.num.value = null;
}

 </script>
</head>
<body>
<h2>ADDITION CALCULATOR</H2>
<form method="post" action="assignment.html" name="calc">
<table border="2" width="160px">
<tr>
<td><p id="labl">&nbsp;</p></td>
</tr>
<tr><td><input type="text" name="num" value="0" id="num"/></td>
</tr>
<tr>
<td>
<input type="button" name="add" value="+" onClick="processVal1();" id="plus" id="plus"/>
<input type="button" name="clr" value="C" onClick="clearVal();"/>
</td>
</tr>
<tr>
<td>
<input type="button" name="equ" value="=" onClick="addVal();" id="equ"/></td>
</tr>
</table>
</form>
</body>
</html>
Share To:

VU Student Support

Post A Comment: