title: Passing parameters on event listeners with loops
body: <p>Just a quick question, can anyone tell me why this doesnt work and how to fix it? Essentially its taking a group of table rows in HTML and dynamically attaching click events to them.</p>
  
  <pre><code>for (var a=index; a&lt;rows.length; a++) {
      tr = rows[a];
      tr.onclick = function() { DropDownManager.onItemClick(tr, a); };
      tr.observe("click", function() { DropDownManager.onItemClick(tr, a); });
  }
  </code></pre>
  
  <p>The problem with this code is that the values passed into DropDownManager.onItemClick are always the last items in the loop, this isn't what im after as i wanted them to be the current value in that stage of the loop. I realize I'm missing something quite simple but cant for the life of me work it out!</p>