Click here to Skip to main content
15,883,853 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Everyone
I want to add add two number that are in two textbox and transfer its value in third textbox using javascript. i am implement this code but addition of thes two number not automatic display in third textbox. please can you tell me where am i worg. can you wright code.
XML
<script type="text/javascript">
//<![CDATA[
var total = (parseInt($('#<%= txtmaxmarks.ClientID %>').val()) + parseInt($('#<%= txtmarks.ClientID %>').val())) * parseInt($('#<%= txtper.ClientID %>').val()); ct100_BodyContent_txtTotalOrder.initialvalue = total;
//]]>
</script>


i am using this code
thanks in advance
Posted
Updated 23-Dec-16 5:28am

Code for adding 2 numbers.

<html>
  <head>
        <title>Input tutorial</title>
        <script language="javascript">
                function addNumbers()
                {
                        var val1 = parseInt(document.getElementById("value1").value);
                        var val2 = parseInt(document.getElementById("value2").value);
                        var ansD = document.getElementById("answer");
                        ansD.value = val1 + val2;
                }
        </script>
  </head>
  <body>
        value1 = <input type="text" id="value1" name="value1" value="1"/>
        value2 = <input type="text" id="value2" name="value2" value="2"/>
        <input type="button" name="Sumbit" value="Click here" onclick="javascript:addNumbers()"/>
        Answer = <input type="text" id="answer" name="answer" value=""/>
  </body>
</html>


Thanks
 
Share this answer
 
Comments
Amir Mahfoozi 7-Jan-12 5:46am    
+5
Sridhar Patnayak 7-Jan-12 5:47am    
Thanks Amir
Sergey Alexandrovich Kryukov 7-Jan-12 6:00am    
All right, a 5.
--SA
Sridhar Patnayak 7-Jan-12 6:05am    
Thanks SAKryukov
Member 8445148 7-Mar-14 6:29am    
thank u for ur support

JavaScript Operators



x = 5, y = 2, calculate z = x + y, and display z:






var x = 5;
var y = 2;
var z = x + y;
document.getElementById("demo").innerHTML = z;



 
Share this answer
 
Comments
Richard MacCutchan 23-Dec-16 13:01pm    
Why are you posting here? This question is nearly 5 years old.
function hi(){
var x=document.getElementById("f").value;
var y=document.getElementById("ff").value;
alert("x ="+x+"y ="+y);
var z=x+y;
alert("z = "+z);// here i getting the answer 56 if the value of x=5 and y=6
document.getElementById("fff").innerHTML=z;

}
 
Share this answer
 
Comments
Richard Deeming 27-Feb-18 11:56am    
Your inability to correctly copy the code from the accepted solution, which was posted SIX YEARS AGO, does not qualify as a new "solution".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900