Hi. I''ve assigned the same event to a set of checkboxes. The handler looks at Event.element(ev) to find which checkbox was selected. I''ve got data coming in from an Ajax connection and the checkboxes are set accordingly in the onSuccess part of the Ajax.Request call. I now want to trigger the click event attached to the checkbox and pass the checkbox as part of the event. Effectively I want to generate the event in JS just like a user would by clicking the checkbox. The handler needs an Event object. This is what I am not sure about how to create. Using prototype.js V1.5.1.1 -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Very simple. Where "c1" is the ID of your checkbox: var link = $(''c1'') link.click(); On Jul 24, 6:58 am, "Richard Quadling" <rquadl...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hi. > > I''ve assigned the same event to a set of checkboxes. The handler looks > at Event.element(ev) to find which checkbox was selected. > > I''ve got data coming in from an Ajax connection and the checkboxes are > set accordingly in the onSuccess part of the Ajax.Request call. > > I now want to trigger the click event attached to the checkbox and > pass the checkbox as part of the event. > > Effectively I want to generate the event in JS just like a user would > by clicking the checkbox. The handler needs an Event object. This is > what I am not sure about how to create. > > Using prototype.js V1.5.1.1 > -- > ----- > Richard Quadling > Zend Certified Engineer :http://zend.com/zce.php?c=ZEND002498&r=213474731 > "Standing on the shoulders of some very clever giants!"--~--~---------~--~----~------------~-------~--~----~ 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 24/07/07, Diodeus <diodeus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Very simple. Where "c1" is the ID of your checkbox: > > var link = $(''c1'') > link.click(); > > > On Jul 24, 6:58 am, "Richard Quadling" <rquadl...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > > Hi. > > > > I''ve assigned the same event to a set of checkboxes. The handler looks > > at Event.element(ev) to find which checkbox was selected. > > > > I''ve got data coming in from an Ajax connection and the checkboxes are > > set accordingly in the onSuccess part of the Ajax.Request call. > > > > I now want to trigger the click event attached to the checkbox and > > pass the checkbox as part of the event. > > > > Effectively I want to generate the event in JS just like a user would > > by clicking the checkbox. The handler needs an Event object. This is > > what I am not sure about how to create. > > > > Using prototype.js V1.5.1.1That''s what I thought. But, in the event handler, Event.element(ev).id results in "has no properties". In the end I had to create a normal function which receives an id and the event handler calls this function. e.g. function clickeventhandler(ev) { clickfunction(Event.element(ev)); } function clickfunction(obj) { ... } Which doesn''t seem right. Now I did put a debug in the eventhandler (Using FF2.0.0.5 and FireBug 1.0.5) and I get 2 debugs. I''m wondering if FB is getting in the way somehow and the method you described would be OK. I''ll try to produce a simpler version as a test case. Thanks. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 25/07/07, Richard Quadling <rquadling-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 24/07/07, Diodeus <diodeus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Very simple. Where "c1" is the ID of your checkbox: > > > > var link = $(''c1'') > > link.click(); > > > > > > On Jul 24, 6:58 am, "Richard Quadling" <rquadl...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > > wrote: > > > Hi. > > > > > > I''ve assigned the same event to a set of checkboxes. The handler looks > > > at Event.element(ev) to find which checkbox was selected. > > > > > > I''ve got data coming in from an Ajax connection and the checkboxes are > > > set accordingly in the onSuccess part of the Ajax.Request call. > > > > > > I now want to trigger the click event attached to the checkbox and > > > pass the checkbox as part of the event. > > > > > > Effectively I want to generate the event in JS just like a user would > > > by clicking the checkbox. The handler needs an Event object. This is > > > what I am not sure about how to create. > > > > > > Using prototype.js V1.5.1.1 > > That''s what I thought. > > But, in the event handler, > > Event.element(ev).id results in "has no properties". > > > In the end I had to create a normal function which receives an id and > the event handler calls this function. > > e.g. > > function clickeventhandler(ev) > { > clickfunction(Event.element(ev)); > } > > function clickfunction(obj) > { > ... > } > > Which doesn''t seem right. > > Now I did put a debug in the eventhandler (Using FF2.0.0.5 and FireBug > 1.0.5) and I get 2 debugs. I''m wondering if FB is getting in the way > somehow and the method you described would be OK. > > I''ll try to produce a simpler version as a test case. > > Thanks.http://pastie.caboo.se/82018 Clicking the second button using FF results in the same id for both calls (that''s the problem). In IE I get a different id for both calls (it works in IE - what a surprise!). -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 Jul 25, 6:23 pm, "Richard Quadling" <rquadl...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> http://pastie.caboo.se/82018 > > Clicking the second button using FF results in the same id for both > calls (that''s the problem).It seems that in Firefox, the target property of the event objects passed to both functions is a reference to the original button. That could be construed as being consistent with the W3C specification - the target property is supposed to point to the element that fires the event. You could use dispatchEvent, say with a fork to dispatchEvent for those browsers that support it and call the click method for those that don''t. Below is a sample function based on code by Mike Winter[1], instead of calling el.click(), call doEventDispatch(el): function doEventDispatch(elm) { var evt = null; if(document.createEvent) { evt = document.createEvent(''MouseEvents''); if(elm && elm.dispatchEvent && evt && evt.initMouseEvent) { evt.initMouseEvent( ''click'', true, // Click events bubble true, // and they can be cancelled document.defaultView, // Use the default view 1, // Just a single click 0, // Don''t bother with co-ordinates 0, 0, 0, false, // Don''t apply any key modifiers false, false, false, 0, // 0 - left, 1 - middle, 2 - right null); // Click events don''t have any targets other than // the recipient of the click elm.dispatchEvent(evt); } } else { elm.click(); } } You might consider a fork for IE''s fireEvent(). 1. http://groups.google.com.au/group/comp.lang.javascript/browse_frm/thread/27e7c70e51ff8a99/98cea9cdf065a524?lnk=gst&q=dispatchEvent+winter&rnum=1&hl=en#98cea9cdf065a524 -- Rob --~--~---------~--~----~------------~-------~--~----~ 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 25/07/07, RobG <rgqld-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:> > > On Jul 25, 6:23 pm, "Richard Quadling" <rquadl...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > > http://pastie.caboo.se/82018 > > > > Clicking the second button using FF results in the same id for both > > calls (that''s the problem). > > It seems that in Firefox, the target property of the event objects > passed to both functions is a reference to the original button. That > could be construed as being consistent with the W3C specification - > the target property is supposed to point to the element that fires the > event. > > You could use dispatchEvent, say with a fork to dispatchEvent for > those browsers that support it and call the click method for those > that don''t. Below is a sample function based on code by Mike > Winter[1], instead of calling el.click(), call doEventDispatch(el): > > > function doEventDispatch(elm) { > var evt = null; > > if(document.createEvent) { > evt = document.createEvent(''MouseEvents''); > > if(elm && elm.dispatchEvent && evt && evt.initMouseEvent) { > evt.initMouseEvent( > ''click'', > true, // Click events bubble > true, // and they can be cancelled > document.defaultView, // Use the default view > 1, // Just a single click > 0, // Don''t bother with co-ordinates > 0, > 0, > 0, > false, // Don''t apply any key modifiers > false, > false, > false, > 0, // 0 - left, 1 - middle, 2 - right > null); // Click events don''t have any targets other than > // the recipient of the click > elm.dispatchEvent(evt); > } > } else { > elm.click(); > } > } > > > You might consider a fork for IE''s fireEvent(). > > 1. > http://groups.google.com.au/group/comp.lang.javascript/browse_frm/thread/27e7c70e51ff8a99/98cea9cdf065a524?lnk=gst&q=dispatchEvent+winter&rnum=1&hl=en#98cea9cdf065a524 > > > -- > RobRob, Thanks for that. Having read the thread, I can see why there is an issue (more or less). Richard. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---