Javascript
<!doctype html>
<html>
<head>
<title>Adding two numbers using JavaScript in HTML</title>
<script>
var num1 = 10;
var num2 = 40;
var sum = num1+num2;
[Link]("Sum of two numbers is " + sum);
</script>
</head>
<body></body>
</html>
JavaScript Program to Add Two Numbers Using Form
and TextBox
Let us see the actual JavaScript program that lets the user give the input using Form and
Textbox.
<!doctype html>
<html>
<head>
<script>
function add()
var num1, num2, sum;
num1 = parseInt([Link]("firstnumber").value);
num2 = parseInt([Link]("secondnumber").value);
sum = num1 + num2;
[Link]("answer").value = sum;
</script>
</head>
<body>
<p>First Number: <input id="firstnumber"></p>
<p>Second Number: <input id="secondnumber"></p>
<button onclick="add()">Add Them</button>
<p>Sum = <input id="answer"></p>
</body>
</html>
Output: