Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



java script code for addition of two numbers

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 02-01-2010
Member
 
Join Date: Dec 2009
Posts: 32
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.

Reply With Quote
  #2  
Old 02-01-2010
Member
 
Join Date: Apr 2008
Posts: 1,948
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>
Reply With Quote
  #3  
Old 02-01-2010
Member
 
Join Date: May 2008
Posts: 2,007
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>
Reply With Quote
  #4  
Old 02-01-2010
Member
 
Join Date: Apr 2008
Posts: 2,000
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
}
Reply With Quote
  #5  
Old 02-01-2010
Member
 
Join Date: May 2008
Posts: 2,291
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
Reply With Quote
  #6  
Old 02-01-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
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>
Reply With Quote
  #7  
Old 05-01-2010
Member
 
Join Date: Nov 2009
Posts: 95
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);

}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "java script code for addition of two numbers"
Thread Thread Starter Forum Replies Last Post
help me to understand java code (calendar java code) ? so0oma Software Development 2 10-01-2011 12:01 AM
Need C program code to count numbers of negative & positive numbers Sarfaraj Khan Software Development 5 16-01-2010 02:00 PM
What is the shell program to calculate addition of two numbers? Shophia_D Software Development 3 09-12-2009 02:34 PM
program to sort numbers in java. Balamani Software Development 3 24-11-2009 10:18 PM
Java Script Addition Problem Magnus Software Development 3 01-06-2009 12:38 PM


All times are GMT +5.5. The time now is 12:23 PM.