title: javascript - onclick happening onload?
body: <p>so I'm a javascript newbie.  I really have no idea what I'm doing.  I'm trying to apply an onclick function to ALL image tags in my document without having to specify anything in-line.  I tried to get an array of every element with the "img" tag and then specify the function to be called onclick for each one, but for some reason showImage is being called once for each image as soon as the page loads and then NOT working on-click.  I call the function clickImages() once at the very end of my document, and showImage() never outside of the following code.</p>
  
  <p>Thanks in advance!   If addition information is needed, let me know.</p>
  
  <pre><code>function clickImages()
  {
  var images = document.getElementsByTagName("img");
  for(var i = 0; i &lt; images.length; i++)
  {
     images[i].onclick=showImage(600, 800, images[i].src);
  }
  }
  
  function showImage(width,height,file)
  { 
  document.getElementById("trailimageid").height = height;
  document.getElementById("trailimageid").width = width;
  document.getElementById("ttimg").src = file; 
  }
  </code></pre>
  
  <p>Oops!  Forgot to mention.  I have this:</p>
  
  <pre><code>document.write('&lt;div id="trailimageid" style="position:absolute;left:0px;top:0px;width:1px;height:1px;border:1px solid #888888;background:#000000;"&gt;&lt;img id="ttimg" src="temp" /&gt;&lt;/div&gt;');
  </code></pre>
  
  <p>Basically what I'm doing is opening the image at the top of the page onclick in a new div.  This is probably a stupid way of doing it now, but I'll have the new div with the image jump to the position of the mouse and follow it around later.</p>