title: Javascript: Uncaught TypeError: Cannot read property 'childNodes' of undefined
body: <p>I have a problem with the following <code>javascript</code> code. When I call the function, in <code>IE</code> or <code>Chrome</code>'s console I get the error:</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'childNodes' of undefined</p>
  </blockquote>
  
  <p>This is the <code>javascript</code>:</p>
  
  <pre><code>function getline(nline) {
      var combo = window.document.getElementById("combox");
      if (nline == activeline) {
          return;
      }
      if (nline &gt; combo.childNodes[0].childNodes.length) return;
      if (nline &lt;= 0) return;
      if (activeline &gt; 0) {
          if (activeline % 2 == 0) combo.childNodes[0].childNodes[activeline - 1].className = "color1";
          else combo.childNodes[0].childNodes[activeline - 1].className = "color2";
      }
      if (nline &gt; 0) {
          combo.childNodes[0].childNodes[nline - 1].className = "current";
          activeline = nline;
      }
      combo.childNodes[0].childNodes[activeline - 1].focus(); }
  </code></pre>
  
  <p>And <code>Chrome</code>'s console says, that the problem is on this line:</p>
  
  <pre><code>if (nline &gt; combo.childNodes[0].childNodes.length) return;
  </code></pre>
  
  <p>I read that using the <code>getelementsbytagname</code> can be a fix, but I don't know how to adapt to this script.</p>
  
  <p>Update: This is the html part:</p>
  
  <pre><code>&lt;script&gt;
    function putfileinit(nline) {
      document.getElementById("divcombo").scrollTop = (nline - 1) * 15;
      getline(nline);
  }
  &lt;/script&gt;
  
  &lt;div id="divcombo" &gt;
      &lt;table id="combox" class="combox" border="0" cellspacing="0" cellpadding="5"&gt;&lt;/table&gt;
  &lt;/div&gt;
  &lt;script DEFER&gt;
      putfileinit(1);
  &lt;/script&gt;
  </code></pre>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks.</p>