PDA

View Full Version : Calculations in Tables using Javascript


toto1026
10-18-2002, 06:27 PM
Hi,

I was wondering if anyone can help me out. Im trying to find out if it is possible to perform calculations within an HTML table such as computing for the Total & Average of a set of values in a column. If anyone can point me to a script which I could possibly use, it would be of great help to me.

Thanks!

Rich

PauletteB
10-18-2002, 07:01 PM
JavaScript Spreadsheets - Google (http://www.google.com/search?q=spreadsheet+javascript&B1=Submit)

toto1026
10-18-2002, 07:07 PM
Thanks Paulette, but not exactly what I was looking for. I need a script to compute data that is already in the HTML table..

RadarBob
10-19-2002, 12:55 AM
Name all the fields the same:
<input type="text" name="sumNumber" value="" onclick="sumNumbers();">

Because they are all the same name you can deal with them like an array, thus:

function sumNumbers() {
var theTotal = 0;

for (var i=0; i<document.myform.sumNumber.length; i++) {
theTotal += parseFloat (document.myform.sumNumber[i]);
}
document.myform.TotalField.value = theTotal;
}// sumNumbers()