We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Friday, July 10, 2015

Mini calculator with javascript

        <html>
<head >
    <title>
    </title>
  <script type="text/javascript">
      var a, b, c;
              function Addition()
              {             
                  a = document.getElementById('txtNum1').value;
                  b = document.getElementById('txtNum2').value;               

                  c = parseInt(a) + parseInt(b);
                  document.getElementById('txtresult').value = c;         
              }
              function Subtraction() {
                  a = document.getElementById('txtNum1').value;
                  b = document.getElementById('txtNum2').value;

                  c = parseInt(a) - parseInt(b);
                  document.getElementById('txtresult').value = c;
              }

              function Multiplication() {

                  a = document.getElementById('txtNum1').value;
                  b = document.getElementById('txtNum2').value;
                  c = parseInt(a) * parseInt(b);
                  document.getElementById('txtresult').value = c;
              }

              function Division() {
                  a = document.getElementById('txtNum1').value;
                  b = document.getElementById('txtNum2').value;
                  c = parseInt(a) / parseInt(b);
                  document.getElementById('txtresult').value = c;
              }

    </script>

</head>
<body>
    <form  name="Calculator">
    <div>
        <div align="center"><h1 style="color:green">Mini Calculator</h1></div>

        <table>
            <tr>
                <td><input type="text" id="txtNum1" name="Number1" />&nbsp;&nbsp;</td>
                <td><input type="button" id="btn1" value="+" onclick="Addition()"/>
                    <br />
                    <input type="button" id="btn2" value="-" onclick="Subtraction()" /><br />
                    <input type="button" id="btn3" value="X" onclick="Multiplication()" /><br />
                    <input type="button" id="btn4" value="/" onclick="Division()" />
                </td><td>&nbsp;&nbsp;<input type="text" id="txtNum2" name="Number2" /></td><td>&nbsp;&nbsp;=&nbsp;&nbsp;</td>
                <td><input type="text" id="txtresult" name="total" /></td>
            </tr>
        </table>
    </div>
    </form>
</body>


</html>

output:

No comments: