What Eric was saying was not that they are all using the same callback, but that they are all referencing the same i variable at the same address in memory, which at the end of your loop holds the value 6. You would have been fine if you had created a locally scoped variable new_i within the loop and used that in the callback (of course Eric's alternative also works fine, but I'm just trying to clear this issue up a little in your mind so you know next time)

This would have worked:

for (var i=1; i<=5;i++){
   var new_i = i;
   Event.observe($('star'+new_i), 'click',
function(e){objRating.setRating(new_i)});
}

On 9/7/06, jumblesale <[EMAIL PROTECTED]> wrote:

Actually, no worries, I figured it out from your example - thanks
loads, that's been causing me headaches!
j







--
Ryan Gahl
Application Development Consultant
Athena Group, Inc.
Inquire: 1-888-919-8700 x2903
Blog: http://www.someElement.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs
-~----------~----~----~----~------~----~------~--~---

Reply via email to