ADVERTISEMENT
ADVERTISEMENT

JavaScript function to add two integer numbers.

This code snippet is used to find sum of two integer numbers using JavaScript function.

Add two integer numbers

HTML and JavaScript:

<!--Add two integer numbers using JavaScript.-->

<html>
   <head>
      <title>Add two integer numbers using JavaScript.</title>
      <script type="text/javascript">
         function addTwoNumbers(textBox1, textBox2){
         	var x=document.getElementById(textBox1).value;
         	var y=document.getElementById(textBox2).value;
         	var sum=0;
         	sum=Number(x)+Number(y);
         	alert("SUM is: " + sum);
         }
      </script>
   </head>
   <body>
      <h1>Add two integer numbers using JavaScript.</h1>
      <b>Enter first Number: </b><br>
      <input type="text" id="textIn1"/><br>
      <b>Enter second Number: </b><br>
      <input type="text" id="textIn2"/><br><br>
      <input type="button" id="btnSum" value="Calculate SUM" onClick="addTwoNumbers('textIn1','textIn2')"/>
   </body>
</html>

Result:

add two numbers using javascript
Click for DEMO →

JavaScript Examples »


ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.