title: Javascript: Uncaught TypeError: Cannot call method 'addEventListener' of null
body: <p>I'm trying to do something fairly simple, but for the reason of me probably not being good enough to search documentation, I can't get this to work.</p>
  
  <p>I have a functioning inline JS that looks like this:</p>
  
  <pre><code>&lt;A title="Wolfram IP Calc" href="javascript:txt=prompt('Enter%20IP%20address,%20e.g.%2010.20.30.40/29','1.2.3.4/5');%20if(txt)%20window.open('http://www.wolframalpha.com/input/?i='+txt);void(O);"&gt;Compute!&lt;/A&gt;
  </code></pre>
  
  <p>For various reasons, I'm trying to seperate the JS, and this is where I hit a snag.</p>
  
  <p>I've created the following test page that gives me the error <code>Uncaught TypeError: Cannot call method 'addEventListener' of null</code>:</p>
  
  <pre><code>&lt;HTML&gt; &lt;HEAD profile="http://www.w3.org/2005/10/profile"&gt; &lt;script type="text/javascript"&gt;
  var compute = document.getElementById('compute');
  compute.addEventListener('click', computeThatThing, false);
  
  function computeThatThing() {
      txt=prompt('Enter%20IP%20address,%20e.g.%2010.20.30.40/29','1.2.3.4/5');
      if(txt) {
          window.open('http://www.wolframalpha.com/input/?i='+txt);
      }
  }
  &lt;/script&gt;&lt;/HEAD&gt;
  &lt;BODY&gt;
  &lt;A title="Wolfram IP Calc" id="compute" href="javascript:void(O);"&gt;Test&lt;/A&gt;
  &lt;/BODY&gt;
  &lt;/HTML&gt;
  </code></pre>
  
  <p>The only thing I've been able to find that points to a problem like that is that <code>addEventListener</code> can't work with <code>&lt;A&gt;</code> but should handle <code>&lt;IMG&gt;</code> (which suits me fine as I'm going to pour this on some images), so I tried adding the following to no avail:</p>
  
  <pre><code>&lt;img id="compute" src="http://products.wolframalpha.com/images/products/products-wa.png" /&gt;
  </code></pre>
  
  <p>Thanks in advance for pointing out what I'm doing wrong. It is probably glaringly obvious, but I have close to zero experience with JS and I have gone mostly by cargo culting when I've needed it until now.</p>