Click here to Skip to main content
15,908,437 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
C#
string valu16 = Convert.ToString(ds2.Tables[0].Rows[0]["amount"]);
                    string valu17 = Convert.ToString(ds2.Tables[0].Rows[1]["amount"]);


JavaScript
TextBox tbval = (TextBox)Page.Form.FindControl(("txt0"));
                    tbval.Text = valu16;

                    TextBox tbval2 = (TextBox)Page.Form.FindControl(("txt1"));
                    tbval2.Text = valu17;

[SNS] How to add two textbox values using javascript.
Posted
Updated 6-Aug-12 0:12am
v3

JavaScript
function methodCompleted(results, context, methodName) {


        document.getElementById("<%=txt3.ClientID%>").value=   parseFloat(document.getElementById("<%=txt0.ClientID%>").value) + parseFloat(document.getElementById("<%=txt1.ClientID%>").value )
 }
 
Share this answer
 
v2
Comments
Vani Kulkarni 6-Aug-12 6:13am    
Are you sure this would give proper sum? As far as I know you will have to do ParseFloat.
Sangramsingh Pawar 6-Aug-12 6:32am    
Iam sorry I forgot to conversion
Try this..please search for your question first..

C#
function CalculateSum()
    {

        var Form = document.frmsum;
        var txtbx1=  Form.txt1.value;
        var txtbx2 = Form.txt2.value;
        
       var allsum = Number(txtbx1)+Number(txtbx2);
        if(!isNaN(allsum) && allsum !=Infinity)
        {
            Form.txtsum.value = allsum;
        }
        return CheckZero()
    }


on page load
 
txtsum.Attributes.Add("onblur", "return CalculateSum()"); 
 
Share this answer
 
Comments
_Amy 6-Aug-12 6:30am    
Oops! I forgot to parse. +5!
2011999 6-Aug-12 8:22am    
not working
AshishChaudha 6-Aug-12 8:26am    
What you are doing??? are you changing the name of Form and other control name??
Considering that you have total textbox present in your page.

JavaScript
function getTotal()
{
    var value1 = parseFloat(document.getElementById("txt0").value);
    var value2 = parseFloat(document.getElementById("txt1").value);
    var total = document.getElementById("txtTotal");
    total.value = value1 + value2;
    
}
 
Share this answer
 
Hi,
You can try this:
JavaScript
function fnTotal(){
	var txt0 = $find('<%= txt0.ClientID%>');
	var txt1 = $find('<%= txt1.ClientID%>');
	var txtTotal = $find('<%= txtTotal.ClientID%>');
	txtTotal = parseFloat(txt0) + parseFloat(txt1);
}




--Amit
 
Share this answer
 
v3
Comments
2011999 6-Aug-12 8:22am    
not working
_Amy 6-Aug-12 8:25am    
Check my updated answer.
2011999 6-Aug-12 8:44am    
error CS1002: ; expected
_Amy 6-Aug-12 8:48am    
This is working fine for me. Where you are writing your JS code? If it is in separate JS file then replace $find with document.getElementById..
2011999 6-Aug-12 8:54am    
.ascx file

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