Calculation of Textbox using javascript

Posted by Shoyebaziz123 under ASP.NET on 6/15/2010 | Views : 5346 | Status : [Member] | Replies : 2
Hi All,
I have in my application a grid in which a no. of textboxes as template field, which can be increamented .....when i enter some value in first textbox the sum of all textbox should be shown in footer textbox..... how can i use javascript for this.... i can't found next textbox to to calcualte first one.....


i have written this code in .js file


function UpdateField(txt1,grid)
{
alert(txt1.value);
var amt1,amt2;
var gvET = document.getElementById(grid);
var rCount =parseInt(grid.rows.length)-2;

// upto this works fine


for( var i=0;i<rCount;i++)
{
var txtval1=document.getElementById(txt1).value !="" ? document.getElementById(txt1).value : "0";
amt2=parseFloat(amt2) + parseFloat( txtval1);
}
alert(amt2);

}


what is going wrong ?

Thanks

//var txtTotOtherAmount=0;
}




Responses

Posted by: SurajRane on: 6/15/2010 [Member] Starter

Up
0
Down
post me detail code and what is your exact reqmt. with example.

Shoyebaziz123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhilan on: 6/16/2010 [Member] Starter

Up
0
Down
you have to increment the textbox id also

ex..
txt1 nexttime txt2 like that


for( var i=0;i<rCount;i++)
{
var fldname="txt"+i;
var txtval1=document.getElementById(fldname).value !="" ? document.getElementById(fldname).value : "0";
amt2 = amt2 + parseFloat(amt2) + parseFloat( txtval1);
}

try like this way

Shoyebaziz123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response