Add two Numbers in JavaScript Inputting from KeyBoard

KeyBoard input in JavaScript:-

As like other programming languages like C, C++, Java, C# etc, JavaScript does not support direct input from console because its not working on console. JavaScript working only on web browser and the interpreter for JavaScript is browser itself.

If you want to get input from keyboard in JavaScript then JavaScript provide two options one is, input from HTML controls like TexBox and second is, prompt().

here is a tutorial for getting input by both the methods:-

Live Demo
Enter Number
Enter Number


<tr><td>Enter Number</td><td><input id="num1" type="text" /></td></tr>
<tr><td>Enter Number</td><td><input id="num2" type="text" /></td></tr>
<tr><td>Result</td><td><input id="res" type="text" /></td></tr>
<tr><td><input onclick="sum()" type="button" value="ADD" /></td></tr>

JavaScript Code

<script type="text/javascript">
function sum()
var n1=parseInt(document.getElementById('num1').value);
var n2=parseInt(document.getElementById('num2').value);

{ 0 comments... read them below or add one }

Post a Comment