Solved

# Get Average of Numbers in a Column of HTML Table

Posted on 2007-03-21

This simple javascript calculates and displays the sum total of the 6th column in a table (which happens to have a header, then 12 rows of data, then a blank row at the bottom, where the sum of column 6 is displayed):

<script>

function calcSum(){

for (j=5;j<6;j++){

sum=0

for (i=1;i<13;i++) sum+=1*document.getElementById("numTable").rows[i].cells[j].innerHTML;

document.getElementById("numTable").rows[i].cells[j].innerHTML=sum

}

}

</script>

Instead of showing the sum of Column 6, however, I would like to show the mean average. How would I modify the script to do that?