Results 1 to 2 of 2

Thread: add html table columns (?)

  1. #1
    Join Date
    Mar 2011

    add html table columns (?)

    Hi *,

    This is my first post here, feeling good to be part of this community.
    The case that brought me here is the following: An html table is printed with data from a database using php. I want to sum every table column and add it to the table. I have used innerHTML to do that, but what i get is every cell containing each column sum is added to the table vertically, one below the other and not horizontally. Another thing that needs to be mentioned is that the table column number may vary from query to query, since the column headers are the months of a specific period of time given by the user.

    Here is the part of the code that intends to print the sums:
    echo "<script language=\"javascript\" type=\"text/javascript\">
    	var tds = document.getElementById('sumtable').getElementsByTagName('td');
    	var t = document.createElement('sumtable');
    	var p = ".$k.";
    	document.getElementById('sumtable').innerHTML += '<th> Total </th>'; 
    	var c=0;
    		var sum = 0;
    		for(var i = 0; i < tds.length; i++) {
    			if(tds[i].className == 'class'+c) {
    				sum += isNaN(tds[i].innerHTML) ? 0 : parseInt(tds[i].innerHTML);
    	document.getElementById('sumtable').innerHTML += '<td align=\"center\">' + sum + '</td>';
    	document.getElementById('sumtable').innerHTML += '</tr>';
    </script> ";
    I think that the problem is created by innerHTML, since in FF I have the aforementioned problem, while in IE, I can't see the sums at all. So, I would like to ask if there is another simpler way of doing this task.

    Thank you very much for your time and interest.

  2. #2
    Join Date
    Mar 2011
    The code above creates the last part of the table starting with "Total". You can see that even if there is no "</tr>" in the part of the while loop where the sums are printed in cells, the innerHTML is printing arbitrarily "</tr>" after each cell.


    Is there a way (maybe other than using innerHTML) to print the total sum cells in the same row?


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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