Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder MaDmiX's Avatar
    Join Date
    Feb 2012
    Location
    Charlotte, NC
    Posts
    173
    Thanks
    44
    Thanked 0 Times in 0 Posts

    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

  • #2
    Regular Coder MaDmiX's Avatar
    Join Date
    Feb 2012
    Location
    Charlotte, NC
    Posts
    173
    Thanks
    44
    Thanked 0 Times in 0 Posts

    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);
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •