I need help in computing for a det of data in a table that is automatically generated by a special program. I have searched for scripts that do this but to no avail.
You say, "the values in the table dynamically change". What makes them change? Is the user changing them? Or, are you running some Java or Javascript that is changing them?
Are the values in the table inside text fields or just simply displayed?
OK. If the other program redraws the entire page, why doesn't it do the calculations? Or, is it just changing the values in the table and NOT redrawing the page?
var values = [];
var table = document.getElementById("myTable"
var trs = table.getElementsByTagName("tr"
// create a multidimensional array
for(var ii = 0; ii < trs.length; ii++)
{
values[ii] = [];
}
// store all values inside all the multidimensional array
for (var trIndex = 0; trIndex < trs.length; trIndex++)
{
var tds = trs[trIndex].getElementsByTagName("td"
var values = [];
var table = document.getElementById("myTable"
var trs = table.getElementsByTagName("tr"
// create a multidimensional array
for(var ii = 0; ii < trs.length; ii++)
{
values[ii] = [];
}
// store all values inside all the multidimensional array
for (var trIndex = 0; trIndex < trs.length; trIndex++)
{
var tds = trs[trIndex].getElementsByTagName("td"
var sums = []
for (var row = 0; row < values[0].length; row++)
{
sums[row] = 0;
for(var col = 0; col < values.length; col++)
{
sums[row] += values[col][row]
}
}
// create a new row
tr = document.createElement("tr"
for (var ii = 0; ii < sums.length; ii++)
{
td = document.createElement("td"
td.innerHTML = sums[ii]
tr.appendChild(td)
}
if (!document.all) // for mozilla and other working browsers
{
table.appendChild(tr)
}
else // for buggy IE
{
var table = document.createElement("table"
table.appendChild(tr)
document.getElementById("totalContainer".innerHTML = table.innerHTML;
}
</script>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.