title: javascript: calling function in for-loop
body: <p>loop that executes a function. However, the following works - the counter counts while the images on the page are loaded.</p>
  
  <pre><code>var progress = function()
   {
     for (var i = 0; i &lt; slide.length; i++)
      slide[i].onload = function(){
           actualprogress +=1,
           loading.innerHTML = actualprogress
      };
   }
  </code></pre>
  
  <p>While the following does <strong>not</strong> work. When I open the Page the counter says "[n]" (number of slides, e.g. "12") from the beginning.</p>
  
  <pre><code>var progress = function()
   {
     var action = function(){
       actualprogress +=1;
       loading.innerHTML = actualprogress
     }
     for (var i = 0; i &lt; slide.length; i++)
       slide[i].onload = action();
   }
  </code></pre>
  
  <p>I would like to call a function from the for-loop because I will need to do other and more things within the function. Why doesn't this work?</p>