title: Javascript: var is null
body: <p>I have this piece of Javascript and it just won't work. I allready checked JSlint but that said everything works. Still doesn't work. The javascript is located not in the HTML but is linked in the <code>&lt;head&gt;</code></p>
  
  <p>note: I am working with a local server, so pageload in instant.</p>
  
  <pre><code>function changeVisibility() {
      var a = document.getElementById('invisible');
      a.style.display = 'block';
  }
  
  var changed = document.getElementById('click1');
  changed.onchange = changeVisibility;
  </code></pre>
  
  <p>This here is the corresponding HTML</p>
  
  <pre><code>&lt;input type="file" name="click[]" size="35" id="click1" /&gt;
  &lt;div id="invisible" style="display: none;"&gt;
    &lt;a href="javascript:addFileInput();"&gt;Attach another File&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>So what happens is I click on the input, select a file and approve. Then then onchange event triggers and the style of my invisible div is set to block.</p>
  
  <p>Problem is, I keep getting this error:</p>
  
  <p>"changed is null:
      changed.onchange = changeVisibility;"</p>
  
  <p>i don't get it, I seriously don't get what I'm overlooking here.</p>
  
  <hr>
  
  <p>EDIT: question answered, thank you Mercutio for your help and everyone else too of course.
  Final code: </p>
  
  <pre><code>function loadEvents() {
      var changed = document.getElementById('click1');
      var a = document.getElementById('invisible');
      document.getElementById('addField').onclick = addFileInput;
  
      changed.onchange = function() {
          a.style.display = 'block';
      }
  }
  if (document.getElementById) window.onload = loadEvents;
  </code></pre>
  
  <p>This here is the corresponding HTML:</p>
  
  <pre><code>&lt;input type="file" name="click[]" size="35" id="click1" /&gt;
  &lt;div id="invisible" style="display: none;"&gt;
    &lt;a href="#"&gt;Attach another File&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Also, thanks for the link to <a href="http://www.jsbin.com" rel="nofollow noreferrer">JSbin</a>, didn't know about that, looks nifty. </p>