Hi All,
I am using the following in a repeating region table cell to return some values from my database:
I am trying to sum these values up using the following script but I am getting an "undefined" error when I call the script.
If I replace the table cell script with a number (say "123") the script works. How can I get it to work with the <td> <script>...</script></td>?
Thanks in advance for any assistance.
Ken
I am using the following in a repeating region table cell to return some values from my database:
Code:
<td><script>document.write(CnvToFrames("<?php echo $row_rstSegmentInfo['EOM']; ?>")-CnvToFrames("<?php echo $row_rstSegmentInfo['SOM']; ?>"));</script></td>
I am trying to sum these values up using the following script but I am getting an "undefined" error when I call the script.
JavaScript:
<script type="text/javascript">
var debugScript = true;
function sumTableColumn(tableId, colNumber) {
// find the table with id attribute tableId
// return the total of the numerical elements in column colNumber
// skip the top row (headers) and bottom row (where the total will go)
var result = 0;
try
{
var tblElem = window.document.getElementById(tableId);
var tblBody = tblElem.getElementsByTagName("tbody").item(0);
var i;
var totalRows = tblBody.rows.length;
for (i=1; i<(totalRows-1); i++) // skip first and last row (hence i=1, and totalRows-1)
{
var currentRow = tblBody.rows[i];
var currentCell = currentRow.cells[colNumber];
var curTextNode = currentCell.childNodes.item(0);
if (debugScript)
{
window.alert("text is " + curTextNode.data);
} // end if
// try to convert text to numeric
var curNumber = parseFloat(curTextNode.data);
// if you didn't get back the value NaN (i.e. not a number), add into result
if (!isNaN(curNumber))
result += curNumber;
} // end for
} // end try
catch (ex)
{
window.alert("Exception in function sumTableColumn()\n" + ex);
result = 0;
}
finally
{
return result;
}
}
function writeResults()
{
if (debugScript)
window.alert("Beginning of function writeResults");
var sumSegTimesFrames = sumTableColumn("segments",6);
try {
var totalSegmentTimeElem = window.document.getElementById("totalSegmentTime");
totalSegmentTimeElem.innerHTML = sumSegTimesFrames;
}
catch (ex)
{
window.alert("Exception in function writeResults()\n" + ex);
}
return;
}
</script>
If I replace the table cell script with a number (say "123") the script works. How can I get it to work with the <td> <script>...</script></td>?
Thanks in advance for any assistance.
Ken