title: document.getElementById returns null when element is part of a form
body: <p>I have <code>php</code> file that has some javascript inside. Consider the following javascript code, which prints <code>null</code> to the console (line 124 in the file):</p>
  
  <pre><code>console.log(document.getElementById('d_min')); 
  </code></pre>
  
  <p>Below the script, I have the following form (line 140 in the file):</p>
  
  <pre><code>&lt;FORM name="DataCollect" ACTION="save_phase1.php" method="post"&gt;
      &lt;input type="hidden" name="d_min" id="d_min" value=""/&gt;
  &lt;/FORM&gt;
  </code></pre>
  
  <p>Why is it that it could be <code>null</code>? Why can't it find that element? </p>
  
  <hr>
  
  <p>I FIXED THE PROBLEM:</p>
  
  <p>I put the entire <code>&lt;form&gt;</code> as a <code>document.write</code> statement after the existing <code>document.write</code> statements I had.</p>