I have a number of select form elements all with a class "extrainfo". What I would like to do is to capture when the select form element is changed and run a function passing the select form elements ID/Name. What is the best way to do this? $$(''.extrainfo'').Event.observe(''change'',myfuntction(id)) --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
DollarDollar returns a collection of matched elements, so the best way is: $$(''.extrainfo'').each(function(element){ Event.observe(element, ''change'', myfuntction(id)) }); http://prototypejs.org/api/enumerable/each -- blog: www.lucaguidi.com Pro-Netics: www.pro-netics.com Sourcesense - making sense of Open Source: www.sourcesense.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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, Luca Guidi wrote:> DollarDollar returns a collection of matched elements, so the best way is: > $$(''.extrainfo'').each(function(element){ > Event.observe(element, ''change'', myfuntction(id)) > }); >Top of my head and not tested, you could also use #invoke, which is simpler: $$(''.extrainfo'').invoke(''observe'', ''change'', myfunction); Notice that you should not execute myfunction(), but pass reference to it to #observe method (unless myfunction(id) returns reference to a function). myfunction will be called with event as first parameter, so you will have to check Event.findElement() to check which <select> was changed, e.g: function myfunction(evnt) { //should alert id of changed <select> alert (Event.findElement(evnt).id); } See Enumerable#invoke docs for details. -- Regards, SWilk --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---