javascript null or not object error - syntax error?
<p>I code a lot in php but not much in javascript.  This script was written to self total a matrix so that both rows and columns are totaled.  Right now it works in compatability mode on IE7 but not otherwise.  I would appreciate a more learned review of the code - I'm guessing it's something simple but I've not figured it out...</p>

<p>I realize it's a bit of code - I've tried to format it for easy review - but I'm really not sure what's up.  I honestly thought it was all good until I changed compatability settings and realized it's hosed everywhere else...</p>

<p>Thank you in advance for your kind consideration - happy to answer any questions or provide additional info!</p>

<pre><code>//declare variables
var sq = new Array();
for (i = 0; i &lt; 50; i++) {
    sq[i] = new Array();
}
var totTot = new Array();
var curCode = new Array();
var curCol = new Array();
var curRow = new Array();
var curVal = new Array();

//following function calculates first the column totals, then the row totals 
//based and finally the intersection of the column and row totals

function calculate(cols, cell, col, row) {
    //verify numeric   
    var numericExpression = /^([1-9][0-9]*(\.[0-9]+)?|0\.[0-9]+|\.[0-9]+|0)$/;
    if (cell.match(numericExpression)) {
        sq[col][row] = cell;
    }
    else {
        sq[col][row] = 0;
        document.getElementById("c" + col + "-r" + row).value = "";
    }
    var colTot = 0;
    var rowTot = 0;
    var total = 0;
    for (r = 0; r &lt; 14; r++) {
        if (sq[col][r] &gt; 0) {
            colTot += (sq[col][r]) * 1;
        } //set column total
        else {
            colTot += 0;
        }
        if (colTot &gt; 0) {
            //write the column total
            document.getElementById('col' + col).innerHTML = colTot;
        }
        //if 0 don't write anything
        else {
            document.getElementById('col' + col).innerHTML = '';
        }
    }
    for (c = 0; c &lt; cols; c++) {
        if (sq[c][row] &gt; 0) { //set row total
            rowTot += (sq[c][row]) * 1;
        }
        else {
            rowTot += 0;
        }
        if (rowTot &gt; 0) {
            //write the row total
            document.getElementById('row' + row).innerHTML = rowTot;
        }
        //nothing if 0
        else {
            document.getElementById('row' + row).innerHTML = '';
        }
        totTot[row] = rowTot * 1;
    }
    for (t = 0; t &lt; 14; t++) {
        if (totTot[t] &gt; 0) {
            total += (totTot[t]) * 1;
        }
        else {
            total += 0;
        }
    }
    if (total &gt; 0) {
        //write total at intersection of row/column total
        document.getElementById('totals').innerHTML = total;
    }
    else {
        document.getElementById('totals').innerHTML = '';
    }
}​
</code></pre>

<p>//this function takes the existing values (previously entered) places them in the grid and runs the 'calculate' function</p>

<pre><code>function getCurValues(cols) {
    for (var a = 0; a &lt; curCode.length; a++) {
        var nameVar = "_" + curCode[a] + "-" + curRow[a];
        document.getElementById(nameVar).value = curVal[a];
        calculate(cols, curVal[a], curCol[a], curRow[a]);
    }​ 
</code></pre>

<p>//following are the arrays that hold the previous data  </p>

<pre><code>curCode[0]='1035';
curVal[0]=5;
curRow[0]=5;
curCol[0]=3;
</code></pre>

<p>//Here's a couple rows of the HTML:</p>

<pre><code>  &lt;table&gt;&lt;tr&gt;
  &lt;td&gt;&lt;input name='_1000-0' type='text' id='c0-r0' class='input' onblur='calculate(3,value,0,0)' size='3' /&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name='_1004-0' type='text' id='c1-r0' class='input' onblur='calculate(3,value,1,0)' size='3' /&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name='_1005-0' type='text' id='c2-r0' class='input' onblur='calculate(3,value,2,0)' size='3' /&gt;&lt;/td&gt;
  &lt;td class='rowTot' width='25px'&gt;&lt;div id='row0'&gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;            
  &lt;td&gt;&lt;input name='_1000-1' type='text' id='c0-r1' class='input' onblur='calculate(3,value,0,1)' size='3' /&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name='_1004-1' type='text' id='c1-r1' class='input' onblur='calculate(3,value,1,1)' size='3' /&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name='_1005-1' type='text' id='c2-r1' class='input' onblur='calculate(3,value,2,1)' size='3' /&gt;&lt;/td&gt;
  &lt;td class='rowTot' width='25px'&gt;&lt;div id='row1'&gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;            
  &lt;td class='colTot'&gt;&lt;div id='col0'&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td class='colTot'&gt;&lt;div id='col1'&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td class='colTot'&gt;&lt;div id='col2'&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td class='totTot'&gt;&lt;div id='totals'&gt;&lt;div&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
</code></pre>
