Like Us Like Us Facebook Subscribe Subscribe us YouTube Whatsapp Share us Whatsapp Query Send your queries

JavaScript adding two integer Computer Lab Btech CSE

JavaScript adding two integer Computer Lab Btech CSE

In this tutorial we will learn how to create a HTML file(add.html) and add two integer using input element (num1 and num2) and submit button. For calculation we will use pure JavaCript.

Create a file name add.html and copy the code given below, save and run in any browser.

This java script programme is extensively used in Jharkhand and West Bengal Btech CSE Lab.

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<table border="1">
<td><label>Enter No. 1</label>
<input type="text" id="num1" value="0">
<label>Enter No. 2</label>
<input type="text" id="num2" value="0">
<td style="text-align:center">
<button onclick="calculate()">Calculate</button>
<td style="text-align:center">
<div id="result"></div>

function calculate(){
var num1=parseInt(document.getElementById("num1").value);
var num2=parseInt(document.getElementById("num2").value);
var sum;
sum = num1+num2;


Run this Programme :

5 1 vote
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments