Eventhandlers in a seperate document
<p>I'd like to keep all my javascripts in a seperate document and I like it that way. Now I've had problems with the last bit of code to move from my HTML-code into my seperate javascript document.</p>

<p>I got two eventhandlers that looked like this:</p>

<pre><code>&lt;a href="http://www.commercial.se" onclick="confirmLeave()" target="_blank"&gt; 
</code></pre>

<p>and</p>

<pre><code>&lt;IMG SRC="folder/pic_small.jpg" alt="Description"  onClick="view(this);"&gt;
</code></pre>

<p>This is the javascript code for the two eventhandlers:</p>

<pre><code>function confirmLeave()
{
  if(confirm("Vill du lämna Blomstermåla-Bladet?")) {
    return true;
  } else {
    if(window.event) {
      window.event.returnValue = false;
    } else {
      e.preventDefault();
    }
    return false;
  }
}
</code></pre>

<p>And </p>

<pre><code>function view(img) {
   imgsrc = img.src.split("_")[0] + "_big.jpg";
   viewwin = window.open(imgsrc,'viewwin', "width=790,height=444,location=0");  
  viewwin.focus();  
}
</code></pre>

<p>I've managed to solve my problem of not having the javascript code in my HTML document for the first onClick eventhandler by changing my HTML to this:</p>

<pre><code>&lt;a href="http://www.commercial.com" id="external-link" target="_blank"&gt; 
</code></pre>

<p>And adding this to my javascript document:</p>

<pre><code>function init()
{
    var link = document.getElementById("external-link");

    link.onclick = confirmLeave;
}

window.onload = init;
</code></pre>

<p>I've tried adding a similar solution to the other eventhandler but I can't figure out the code I need to use for it to work. I would like to know how to add that event handler into the init function as well.</p>
