Add Two Numbers And Display Result In Textbox With Javascript
I was just trying to write a simple javascript program that will demonstrate to take user input from text field, and clicking the button will display the summation result of those
Solution 1:
Here a working fiddle: http://jsfiddle.net/sjh36otu/
functionadd_number() {
var first_number = parseInt(document.getElementById("Text1").value);
var second_number = parseInt(document.getElementById("Text2").value);
var result = first_number + second_number;
document.getElementById("txtresult").value = result;
}
Solution 2:
When you assign your variables "first_number" and "second_number", you need to change "document.getElementsById" to the singular "document.getElementById".
Solution 3:
var first_number = parseInt(document.getElementById("Text1").value);
var second_number = parseInt(document.getElementById("Text2").value);
// This is because your method .getElementById has the letter 's': .getElement**s**ById
Solution 4:
<script>functionsum()
{
var value1= parseInt(document.getElementById("txtfirst").value);
var value2=parseInt(document.getElementById("txtsecond").value);
var sum=value1+value2;
document.getElementById("result").value=sum;
}
</script>
Post a Comment for "Add Two Numbers And Display Result In Textbox With Javascript"