sbornstein2
asked on
Need a Calculate Table Column Total Function
I have some ASP pages where I need to figure out how to calculate a total of all rows I am writing out. I am writing table rows and columns. What I did was for each column in ASP I added a number to the TD tag such as
<TR>
<TD name=COL1TOTAL1>
</TD>
<TD name=COL2TOTAL1>
</TD>
<TD name=COL3TOTAL1>
</TD>
</TR>
<TR>
<TD name=COL1TOTAL2>
</TD>
<TD name=COL2TOTAL2>
</TD>
<TD name=COL3TOTAL2>
</TD>
</TR>
I did not know if I should use textboxes instead but I am only writing out values. I am thinking I can probably just do this within the ASP Code as well, but I want to know if there is a Javascript Total Function where I can do something like this and for each Column do some loop and a string parse to loop and grab each Column name and total that column. Then I am looking for something to handle a row as well like ROW1TOTAL, ROW2TOTAL. Anyone have anything I can play with. Thanks
<TR>
<TD name=COL1TOTAL1>
</TD>
<TD name=COL2TOTAL1>
</TD>
<TD name=COL3TOTAL1>
</TD>
</TR>
<TR>
<TD name=COL1TOTAL2>
</TD>
<TD name=COL2TOTAL2>
</TD>
<TD name=COL3TOTAL2>
</TD>
</TR>
I did not know if I should use textboxes instead but I am only writing out values. I am thinking I can probably just do this within the ASP Code as well, but I want to know if there is a Javascript Total Function where I can do something like this and for each Column do some loop and a string parse to loop and grab each Column name and total that column. Then I am looking for something to handle a row as well like ROW1TOTAL, ROW2TOTAL. Anyone have anything I can play with. Thanks
ASKER
I have a table and within that table I have ASP code that will write out a new row dynamically for each record. Each record will have 4 columns, Order1 Amt, Order2 Amt, Order3 Amt, Total Order. Then when the row gets written I am just adding a number to each column name, I thought this might allow me to loop through and calc totals on each column, if not then just ignore it. So it looks like this
<TABLE>
<TR>
<TD name="Order1Amt-1">50.00
</TD>
<TD name="Order2Amt-1">60.00
</TD>
<TD name="Order3Amt-1">70.00
</TD>
<TD name="OrderTotal-1">180.00
</TD>
</TR>
<TR>
<TD name="Order1Amt-2">20.00
</TD>
<TD name="Order2Amt-2">30.00
</TD>
<TD name="Order3Amt-2">20.00
</TD>
<TD name="OrderTotal-2">70.00
</TD>
</TR>
<TR>
<TD name="Order1Amt-3">10.00
</TD>
<TD name="Order2Amt-3">15.00
</TD>
<TD name="Order3Amt-3">8.00
</TD>
<TD name="OrderTotal-3">33.00
</TD>
</TR>
--The loop will end once the records all write out. Now I need a total row to total each column like this.
<TR>
<TD name="TOTALORDER1">80.00
</TD>
<TD name="TOTALORDER2">105.00
</TD>
<TD name="TOTALORDER3">98.00
</TD>
<TD name="TOTALORDERS">283.00
</TD>
</TR>
</TABLE>
That last row is what I am looking to calc with Javascript and also potentialy later the Row Totals across if possible.
<TABLE>
<TR>
<TD name="Order1Amt-1">50.00
</TD>
<TD name="Order2Amt-1">60.00
</TD>
<TD name="Order3Amt-1">70.00
</TD>
<TD name="OrderTotal-1">180.00
</TD>
</TR>
<TR>
<TD name="Order1Amt-2">20.00
</TD>
<TD name="Order2Amt-2">30.00
</TD>
<TD name="Order3Amt-2">20.00
</TD>
<TD name="OrderTotal-2">70.00
</TD>
</TR>
<TR>
<TD name="Order1Amt-3">10.00
</TD>
<TD name="Order2Amt-3">15.00
</TD>
<TD name="Order3Amt-3">8.00
</TD>
<TD name="OrderTotal-3">33.00
</TD>
</TR>
--The loop will end once the records all write out. Now I need a total row to total each column like this.
<TR>
<TD name="TOTALORDER1">80.00
</TD>
<TD name="TOTALORDER2">105.00
</TD>
<TD name="TOTALORDER3">98.00
</TD>
<TD name="TOTALORDERS">283.00
</TD>
</TR>
</TABLE>
That last row is what I am looking to calc with Javascript and also potentialy later the Row Totals across if possible.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. :)
I'm not exactly sure what you're asking. Calculate the totals of what columns in what table? Can you elaborate please?
Regards,
Zyloch