use javascript to sum the columns and rows in a dynamically created php table
<p>I've been searching and searching for a javascript to sum the columns and rows in a dynamically created php table. I'm new to php and my javascript is rusty to say the least. I need to sum user input (both columns and rows). The number of rows depends on how many student numbers have been entered into the database. Any help anyone can provide would be gratefully accepted!</p>

<p>Here is my code so far:</p>

<pre><code>&lt;?php
session_start();
echo $_SESSION['CNAQID'];
echo "&lt;br/&gt;";
echo $_SESSION['coursename'];

echo "&lt;table id= 'sum_table' border = '1' border-style = 'dotted' border-width = '1px' bordercolor= '#000000' nowrap= 'nowrap' width = '100%' &gt;";
echo "&lt;tr&gt;&lt;td&gt;&lt;font color = 'blue'&gt;ID&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font color = 'blue'&gt;CNAQID&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font color = 'blue'&gt;First Name&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font color = 'blue'&gt;Last Name&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font color = 'blue'&gt;Q1&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font color = 'blue'&gt;Q2&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font color = 'blue'&gt;Q3&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font color = 'blue'&gt;Q4&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font color = 'blue'&gt;Q5&lt;/font&gt;&lt;/td&gt;&lt;td&gt;&lt;font color = 'blue'&gt;Total Score&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;";
echo "&lt;form method='POST' action='speakingdatatransation.php'&gt;";
while ($row = mysql_fetch_array($result))   
{   
$i=1;
$a= 0;
$b=1;
$c=2;
$d=3;
$_POST[$a] = $row[$a];  
$_POST[$b] = $row[$b];
$_POST[$c] = $row[$c];
$_POST[$d] = $row[$d];
echo '&lt;tr&gt;&lt;td height="15"&gt;&lt;input name="id[]" type="text" id="id[]" size="5" value= "'.$_POST[$a].'" /&gt;

&lt;td height="15"&gt;&lt;input name="cnaqid[]" type="text" id="cnaqid[]" size="5" value= "'.$_POST[$b].'" /&gt;

&lt;td height="15"&gt;&lt;input name="firstname[]" type="text" id="firstname[]" size="5" value= "'.$_POST[$c].'" /&gt;

&lt;td height="15"&gt;&lt;input name="lastname[]" type="text" id="lastname[]" size="5"" value= "'.$_POST[$d].'"/&gt;

&lt;td height="15"&gt;&lt;input name="q1[]" type="text" id="q1[]" onblur="recalculateSum1()" onchange="updateTotal(this)" size="5" value = "" /&gt;

&lt;td height="15"&gt;&lt;input name="q2[]" type="text" id="q2[]" onblur="recalculateSum2()" onchange="updateTotal(this)" size="5" value = ""/&gt;

&lt;td height="15"&gt;&lt;input name="q3[]" type="text" id="q3[]" onblur="recalculateSum3()" onchange="updateTotal(this)" size="5" value = "" /&gt;

&lt;td height="15"&gt;&lt;input name="q4[]" type="text" id="q4[]" onblur="recalculateSum4()" onchange="updateTotal(this)" size="5" value = ""/&gt;

&lt;td height="15"&gt;&lt;input name="q5[]" type="text" id="q5[]" onblur="recalculateSum5()" onchange="updateTotal(this)" size="5" value = ""/&gt;

&lt;td height="15"&gt;&lt;input name="totalscore[]" type="text" id="totalscore[]" size="5" value = "0" /&gt;&lt;/tr&gt;';
}

    echo '&lt;tr&gt;&lt;td height="15"&gt;&lt;input name="total[]" type="hidden" id="total[]" size="5"" value= "" /&gt;
    &lt;td height="15"&gt;&lt;input name="total[]" type="hidden" id="total[]" size="5" value= "" /&gt;
    &lt;td height="15"&gt;&lt;input name="total[]" type="hidden" id="total[]" size="5" value= "" /&gt;
    &lt;td height="15"&gt;&lt;input name="total[]" type="hidden" id="total[]" size="5" value= "" /&gt;
    &lt;td height="15"&gt;&lt;input name="total1" type="text" id="total1" size="5" value= "0" /&gt;
    &lt;td height="15"&gt;&lt;input name="total2" type="text" id="total2" size="5" value= "0" /&gt;
    &lt;td height="15"&gt;&lt;input name="total3" type="text" id="total3" size="5" value= "0" /&gt;
    &lt;td height="15"&gt;&lt;input name="total4" type="text" id="total4" size="5" value= "0" /&gt;
    &lt;td height="15"&gt;&lt;input name="total5" type="text" id="total5" size="5" value= "0" /&gt;
    &lt;td height="15"&gt;&lt;input name="total[]" type="hidden" id="total[]" size="5" value= "" /&gt;';

    echo "&lt;tr&gt;&lt;td&gt;&lt;input type='submit' name='submit' id='Submit'     value='Submit' /&gt;&lt;/td&gt;&lt;/tr&gt;";
    echo "&lt;tr&gt;&lt;font color = 'red'&gt;End of database.&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;";

    mysql_close($con);
        }

?&gt;
&lt;/table&gt;
&lt;?php
//mysql_close($con);
}
}

?&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
