I try to build a sum horizontally (for the begining) of some text fields in a table using DOM methods. Unfortunately the final asignment works only for IE. Moz does not show any error message, but does not assign the sum. Any ideeas?
[code=php]
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<meta http-equiv=”Content-Style-Type” content=”text/css”>
<meta http-equiv=”Content-Script-Type” content=”text/javascript”>
<script language=”JavaScript” type=”text/JavaScript”>
function calculate(c){
d=document.getElementById(‘tab’);
totRow=0;
for(var i=0;i<d.rows.length;i++){
for(var j=0;j<d.rows[i].cells.length;j++){
if(c.parentNode==d.rows[i].cells[j]){
for (k=0;k<d.rows[i].cells.length-1;k++){
totRow=totRow+Number(d.rows[i].cells[k].firstChild.value);
}
d.rows[i].cells[d.rows[i].cells.length-1].firstChild.value=totRow;//this line works in IE only
}
}
}
}
</script>
</head>
<body>
<form>
<table border=”0″ cellpadding=”4″ id=”tab”>
<tr>
<td><input type=”text” onkeyup=”calculate(this)”></td>
<td><input type=”text” onkeyup=”calculate(this)”></td>
<td bgcolor=”#CCCCCC”>
<input type=”text” readonly=”true”></td>
</tr>
<tr>
<td><input type=”text” onkeyup=”calculate(this)”></td>
<td><input type=”text” onkeyup=”calculate(this)”></td>
<td bgcolor=”#CCCCCC”>
<input type=”text” readonly=”true”></td>
</tr>
<tr>
<td><input type=”text” onkeyup=”calculate(this)”></td>
<td><input type=”text” onkeyup=”calculate(this)”></td>
<td bgcolor=”#CCCCCC”>
<input type=”text” readonly=”true”></td>
</tr>
<tr bgcolor=”#CCCCCC”>
<td>
<input type=”text” readonly=”true”></td>
<td>
<input type=”text” readonly=”true”></td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>