Greetings; Inside the init() for my class I am assigning event handlers and want to use the same handler function for 2 separate elements so I am using the following code: $(''element1'',''element2'').onchange this.EventHandlerFunction.bindAsEventListener(this); I assumed since I can chain elements inside the $() function that the functionality would allow for this. It doesnt. It doesn''t catch the event for either element at all. When I seperate the code into 2 lines and assign the function to each element independently it works fine: $(''element1'').onchange this.EventHandlerFunction.bindAsEventListener(this); $(''element2'').onchange this.EventHandlerFunction.bindAsEventListener(this); I dont have a problem with doing that but I would much prefer to use the former to remain consistent with $(). I havent looked much into the source to find where it is stopping but is this a bug?? Should I report it? Thanks ahead of time, Kev --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jan 30, 2008 6:57 PM, kaydub <kevwilliams-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> $(''element1'',''element2'').onchange > this.EventHandlerFunction.bindAsEventListener(this);When you pass multiple element ID''s, you get an array of elements instead of an individual element. Since you want to attach the event listener to each object, you need to iterate on the array and attach the listener to each individual element. $(''element1'', ''element2'').each(function(element){ element.observe(''change'', this.changeHandler.bindAsEventListener(this)); }.bind(this)); You *could* use invoke instead to turn this into a one-line operation, but I think the above code example more clearly shows what''s going on. -justin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
100% Spot on. Thanks alot. On Jan 31, 11:15 am, "Justin Perkins" <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jan 30, 2008 6:57 PM, kaydub <kevwilli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > $(''element1'',''element2'').onchange > > this.EventHandlerFunction.bindAsEventListener(this); > > When you pass multiple element ID''s, you get an array of elements > instead of an individual element. Since you want to attach the event > listener to each object, you need to iterate on the array and attach > the listener to each individual element. > > $(''element1'', ''element2'').each(function(element){ > element.observe(''change'', this.changeHandler.bindAsEventListener(this)); > > }.bind(this)); > > You *could* use invoke instead to turn this into a one-line operation, > but I think the above code example more clearly shows what''s going on. > > -justin--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
$(''element1'',''element2'').each(function(e) { e.onchange = this.EventHandlerFunction.bind(this); }.bind(this)); However, I''d strongly advise using Event.observe instead like so: $(''element1'',''element2'').invoke(''change'', this.EventHandlerFunction.bind(this)); Best, Tobie On Jan 31, 1:57 am, kaydub <kevwilli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Greetings; > > Inside the init() for my class I am assigning event handlers and want > to use the same handler function for 2 separate elements so I am using > the following code: > > $(''element1'',''element2'').onchange > this.EventHandlerFunction.bindAsEventListener(this); > > I assumed since I can chain elements inside the $() function that the > functionality would allow for this. It doesnt. > > It doesn''t catch the event for either element at all. > > When I seperate the code into 2 lines and assign the function to each > element independently it works fine: > > $(''element1'').onchange > this.EventHandlerFunction.bindAsEventListener(this); > $(''element2'').onchange > this.EventHandlerFunction.bindAsEventListener(this); > > I dont have a problem with doing that but I would much prefer to use > the former to remain consistent with $(). > > I havent looked much into the source to find where it is stopping but > is this a bug?? Should I report it? > > Thanks ahead of time, > Kev--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
oops! $(''element1'',''element2'').invoke(''observe'', ''change'', this.EventHandlerFunction.bind(this)); cf.: http://prototypejs.org/api/enumerable/invoke http://prototypejs.org/api/element/observe On Jan 31, 2:24 am, Tobie Langel <tobie.lan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> $(''element1'',''element2'').each(function(e) { > e.onchange = this.EventHandlerFunction.bind(this); > > }.bind(this)); > > However, I''d strongly advise using Event.observe instead like so: > > $(''element1'',''element2'').invoke(''change'', > this.EventHandlerFunction.bind(this)); > > Best, > > Tobie > > On Jan 31, 1:57 am, kaydub <kevwilli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Greetings; > > > Inside the init() for my class I am assigning event handlers and want > > to use the same handler function for 2 separate elements so I am using > > the following code: > > > $(''element1'',''element2'').onchange > > this.EventHandlerFunction.bindAsEventListener(this); > > > I assumed since I can chain elements inside the $() function that the > > functionality would allow for this. It doesnt. > > > It doesn''t catch the event for either element at all. > > > When I seperate the code into 2 lines and assign the function to each > > element independently it works fine: > > > $(''element1'').onchange > > this.EventHandlerFunction.bindAsEventListener(this); > > $(''element2'').onchange > > this.EventHandlerFunction.bindAsEventListener(this); > > > I dont have a problem with doing that but I would much prefer to use > > the former to remain consistent with $(). > > > I havent looked much into the source to find where it is stopping but > > is this a bug?? Should I report it? > > > Thanks ahead of time, > > Kev--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Even better. Very easy to read. Thanks to both of you and Prototype Developers for making that functionality kick soo much arse .. Here I was thinking it wasnt gonna happen.. Last time I think that.. On Jan 31, 11:29 am, Tobie Langel <tobie.lan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> oops! > > $(''element1'',''element2'').invoke(''observe'', ''change'', > this.EventHandlerFunction.bind(this)); > > cf.:http://prototypejs.org/api/enumerable/invokehttp://prototypejs.org/api/element/observe > > On Jan 31, 2:24 am, Tobie Langel <tobie.lan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > $(''element1'',''element2'').each(function(e) { > > e.onchange = this.EventHandlerFunction.bind(this); > > > }.bind(this)); > > > However, I''d strongly advise using Event.observe instead like so: > > > $(''element1'',''element2'').invoke(''change'', > > this.EventHandlerFunction.bind(this)); > > > Best, > > > Tobie > > > On Jan 31, 1:57 am, kaydub <kevwilli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Greetings; > > > > Inside the init() for my class I am assigning event handlers and want > > > to use the same handler function for 2 separate elements so I am using > > > the following code: > > > > $(''element1'',''element2'').onchange > > > this.EventHandlerFunction.bindAsEventListener(this); > > > > I assumed since I can chain elements inside the $() function that the > > > functionality would allow for this. It doesnt. > > > > It doesn''t catch the event for either element at all. > > > > When I seperate the code into 2 lines and assign the function to each > > > element independently it works fine: > > > > $(''element1'').onchange > > > this.EventHandlerFunction.bindAsEventListener(this); > > > $(''element2'').onchange > > > this.EventHandlerFunction.bindAsEventListener(this); > > > > I dont have a problem with doing that but I would much prefer to use > > > the former to remain consistent with $(). > > > > I havent looked much into the source to find where it is stopping but > > > is this a bug?? Should I report it? > > > > Thanks ahead of time, > > > Kev--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---