java script code for addition of two numbers
Hi friends,
I am coding one java script program. The desired out-put of this java script code should be the addition of the two given numbers. I have one code for this but it doesn't run correctly, so I need your help.
Please let me know any java script code for addition of two numbers. I Would appreciate your help.
Re: java script code for addition of two numbers
Hello friend,
Use below java script code in your program to print the addition of two numbers:
HTML Code:
<script type="text/javascript">
function AddJavaSc()
{
var k, l;
l=parseInt(document.getElementById("txtVal1").value);
k=parseInt(document.getElementById("txtVal2").value);
document.getElementById("txtVal3").value=l + k;
}
</script>
Re: java script code for addition of two numbers
Javascript code for addition:
Quote:
<Html>
<head>
<script language="JAVASCRIPT">
function addTWONumbers()
{
var num1 = parseInt(document.getElementById("num value1").value);
var num2 = parseInt(document.getElementById("num value2").value);
var ansD = document.getElementById("Addition");
ansTD.value = num1 + num2;
}
</script>
</head>
<Body text ="red">
numvalue1 = <input type="text" name="numvalue1" id="numvalue1" value="1"/>
numvalue2 = <input type="text" name="numvalue2" id="numvalue2" value="2"/>
<input type="Button" value="Click " name="Submit" onclick="javascript:addTWNumbers()"/>
</Body>
</html>
Re: java script code for addition of two numbers
Hi,
To print the addition of two numbers using java script you need to use the one function. First you need to pass two numbers to that java script function. implement the "addition code" in the that function. The function will take two number as input and will give back the addition.
HTML Code:
function addDemo(v1, v2)
{
ans1.value = v1 + V2
}
Re: java script code for addition of two numbers
I think you should use the alert function of the javascript to calculate addition. Use something below in you program:
HTML Code:
var t = '963';
var y = '852;
var h = parseInt(t) + parseInt(y);
Alert(h); //It will show the addition
Re: java script code for addition of two numbers
I have following java script program for addition, copy this java script program and run on your computer:
HTML Code:
<HTML>
<head>
<title>Addition code</title>
<script type="text/javascript">
function AddJS()
{
var x=document.getElementById("txtval1").value;
var z=document.getElementById("txtval2").value;
document.getElementById("txt3").value=x + z;
}
</script>
</head>
<body>
B:
<input id="txtVAl1"type="text" >
N:
<input id="txtval2"type="text" >
AdditionResult:
<input id="txtval3" type="text" >
<input onclick="AddJS()" type="button" id="btnSt" value="Submit" >
</body>
</HTML>
Re: java script code for addition of two numbers
HTML Code:
function get_Two_sum()
{
If (document.getElementById("BNM1").value == "")
document.getElementById("BNM1").value= 0;
If (document.getElementById("BNM2").value == "")
document.getElementById("BNM2").value= 0;
document.getElementById("BNM3").value= parseInt (document.getElementById("BNM1").value) + parseInt (document.getElementById("BNM2").value);
}