title: Javascript: Uncaught TypeError: Cannot read property 'rows' of null
body: <p>He's the JavaScript that's giving me an error of "Uncaught TypeError: Cannot read property 'rows' of null"</p>
  
  <pre><code>var table = document.getElementById("table"),rIndex;
  
  for(var i = 1; i &lt; table.rows.length; i++)
  {
      table.rows[i].onclick = function()
      {
          rIndex = this.rowIndex;
          console.log(rIndex);
  
          document.getElementById("id").value = this.cells[0].innerHTML;
          document.getElementById("nome").value = this.cells[1].innerHTML;
          document.getElementById("morada").value = this.cells[2].innerHTML;
          document.getElementById("localidade").value = this.cells[3].innerHTML;
          document.getElementById("telefone").value = this.cells[4].innerHTML;
          document.getElementById("codpostal").value = this.cells[5].innerHTML;
          document.getElementById("email").value = this.cells[6].innerHTML;
      };
  }
  
  
  // edit the row
  function editRow()
  {
      table.rows[rIndex].cells[0].innerHTML = document.getElementById("id").value;
      table.rows[rIndex].cells[1].innerHTML = document.getElementById("nome").value;
      table.rows[rIndex].cells[2].innerHTML = document.getElementById("morada").value;
      table.rows[rIndex].cells[3].innerHTML = document.getElementById("localidade").value;
      table.rows[rIndex].cells[4].innerHTML = document.getElementById("telefone").value;
      table.rows[rIndex].cells[5].innerHTML = document.getElementById("codpostal").value;
      table.rows[rIndex].cells[6].innerHTML = document.getElementById("email").value;
  }
  </code></pre>
  
  <p>What is wrong with the code ?</p>