Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-20-2012, 09:09 PM   PM User | #1
MaDmiX
Regular Coder

 
Join Date: Feb 2012
Location: Charlotte, NC
Posts: 104
Thanks: 26
Thanked 0 Times in 0 Posts
MaDmiX is an unknown quantity at this point
Need help totaling a table column

Hi All,

I have the following function that calls a function to calculate time and then writes the result to a table cell. I need to sum the results at the bottom row of the table. For some reason I am getting NaN. I tried using parseFloat() to make sure my variable was being interpreted as a number but no luck. Any help is appreciated.

Code:
function outageLength() {
  var rows=document.getElementById("vari").getElementsByTagName("tr");

  for (var x = 1; x < rows.length-1; x++) { //start at 1 to skip the header cells
    var start=rows[x].cells[0].innerHTML;
    var end=rows[x].cells[1].innerHTML;
    var rowTotal=calculateTime(start,end);
    rows[x].cells[4].innerHTML=rowTotal;

    var rowSecs=TimeToSecs(rowTotal);
    rowSecs=parseFloat(rowSecs);
    var totalSecs;
    totalSecs += rowSecs;
  }
  var grandTotalElem = window.document.getElementById("grandTotal");
  grandTotalElem.innerHTML=totalSecs;
}
Thanks in advance,

Ken
MaDmiX is offline   Reply With Quote
Old 09-20-2012, 09:25 PM   PM User | #2
MaDmiX
Regular Coder

 
Join Date: Feb 2012
Location: Charlotte, NC
Posts: 104
Thanks: 26
Thanked 0 Times in 0 Posts
MaDmiX is an unknown quantity at this point
SOLVED: Need help totaling a table column

Code:
function outageLength() {
  var rows=document.getElementById("vari").getElementsByTagName("tr");
  var result=0;

  for (var x = 1; x < rows.length-1; x++) { //start at 1 to skip the header cells
    var start=rows[x].cells[0].innerHTML;
    var end=rows[x].cells[1].innerHTML;
    var rowTotal=calculateTime(start,end);
    rows[x].cells[4].innerHTML=rowTotal;

    var rowSecs=TimeToSecs(rowTotal);
    totalSecs=parseFloat(rowSecs);

  if (!isNaN(totalSecs))
    result += rowSecs;
  }
  var grandTotalElem = window.document.getElementById("grandTotal");
  grandTotalElem.innerHTML=SecsToTime(result);
}
MaDmiX is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:01 AM.


Advertisement
Log in to turn off these ads.