title: javascript: TypeError: document.getElementById("myTable") is null
body: <p>i'm getting the following error:</p>
  
  <pre><code>TypeError: document.getElementById("myTable") is null
  </code></pre>
  
  <p>on document.write(document.getElementById("myTable").rows[i].innerHTML);
  It goes into a never ending loop.</p>
  
  <p>Can someone tell me on what i'm doing wrong? Thank you.</p>
  
  <p>My code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function colorRows(){
  count=document.getElementById("myTable").rows.length;
  alert("count is:"+count);
              for (i=0;i&lt;=count;i++){
                  if (i%2===0){
                      document.write(document.getElementById("myTable").rows[i].innerHTML);
                  }
              }
  }
  &lt;/script&gt; 
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;table id="myTable"&gt;
  
  &lt;tr&gt;
      &lt;th&gt;emp_id&lt;/th&gt;
      &lt;th&gt;name&lt;/th&gt;
      &lt;th&gt;age&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;vaani&lt;/td&gt;
      &lt;td&gt;35&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;Ramu&lt;/td&gt;
      &lt;td&gt;37&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;Iniyan&lt;/td&gt;
      &lt;td&gt;5&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;4&lt;/td&gt;
      &lt;td&gt;Mickey&lt;/td&gt;
      &lt;td&gt;10&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;form method="post" action="JavaScript:colorRows();"&gt;
  &lt;input type="submit" value="Submit" /&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>