title: Onclick function arguments
body: <p>I am trying to simulate a number counting up from 0 to 100 and I am having issues.
  First I tried to use a for loop and send the iteration values to an <code>.innerHTML div</code>but it only showed the last number. So I searched online for a an animated javascript counter and I found this one: <a href="http://jsfiddle.net/jfriend00/aJrj4/" rel="nofollow">http://jsfiddle.net/jfriend00/aJrj4/</a>.</p>
  
  <p>It works for my needs however I am not sure how to apply this so that it can be triggered by a button. This script is written with argument inputs when the function is defined, and then passes them at the end by running the function after wards. 
  I cant figure out how do I input arguments for an <code>onclick</code> event?
  This was my attempt but I keep getting errors, specifically with the <code>onclick</code> line.</p>
  
  <pre><code>var loadSim_btn = document.getElementsByTagName('button')[0];
  
  loadSim_btn.onclick=function load_Sim(pCent, 25, 100, 2000);
  
  function load_Sim (pCent, start, end, duration) {
    var range = end - start;
          // no timer shorter than 50ms (not really visible any way)
          var minTimer = 50;
          // calc step time to show all interediate values
          var stepTime = Math.abs(Math.floor(duration / range));
          // never go below minTimer
          stepTime = Math.max(stepTime, minTimer);
          // get current time and calculate desired end time
          var startTime = new Date().getTime();
          var endTime = startTime + duration;
          var timer;
  
          function run() {
              var now = new Date().getTime();
              var remaining = Math.max((endTime - now) / duration, 0);
              var value = Math.round(end - (remaining * range));
              obj.innerHTML = value;
              if (value == end) {
                  clearInterval(timer);
              }
          }
  
          timer = setInterval(run, stepTime);
          run();
      }
  </code></pre>
  
  <p><strong>ANSWER:</strong>
  So the from what I can tell one issue was I forgot the obj definition line. In addition Joshua Davison answered my main question. 
  "The onclick callback doesn't provide arguments, so we wrap the function call in an anonymous function (that takes no arguments)"
  So my options for assigning the button in java script was:</p>
  
  <blockquote>
    <p>loadSim_btn.onclick=function() { load_Sim(pCent, 25, 100, 2000); }</p>
  </blockquote>
  
  <p>and using an Event Listener:</p>
  
  <blockquote>
    <p>loadSim_btn.addEventListener("click", function() { load_Sim(pCent,
    25, 100, 2000); }, true);</p>
  </blockquote>