adding two numbers from input box values - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Number

Description

adding two numbers from input box values

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script>
function addFunction() {//  ww w. j av a 2  s  .  c o m
    var x = parseInt(document.getElementById("firstInput").value);
    var y = parseInt(document.getElementById("secondInput").value);
    var sum=x+y;
    console.log('Sum is:'+sum);
}

      </script> 
   </head> 
   <body> 
      <input type="text" id="firstInput">
      <br> 
      <input type="text" id="secondInput" onchange="myFunction()">
      <br> 
      <input type="button" value="Add" onclick="addFunction()">  
   </body>
</html>

Related Tutorials