On Sat, Sep 12, 2009 at 12:59 AM, batman42ca <[email protected]> wrote: > > I thought I read somewhere that there was a way to do this. Here's my > non working code: > > var myArray = ["one","two","three"]; > var myValue = [2,4,6]; > > function myFunction() { > var index; > for (index = 0; index < myArray.length; index++) { > $(myArray[index]).addEvent("click",function(event) { > alert(myValue[index]); > }); > } > } // end of myFunction > > myFunction(); > } > > I understand why it fails. The current value of "index" (= 3 after > loop completion) is used when the event triggers. How do I get around > this? I need to use the value of "index" while the loop is running, > not the value of index after the loop is complete.
use bindWithEvent. Regards Rajeev J Sebastian
