Is there a standard way of programmatically firing an event on an element? I think this code works in IE but not FF: myElement.fireEvent(''onclick''); I really only care about IE and FF, but anything else is a bonus. I didn''t see anything in prototype/scriptaculous for this, but I might have missed it. Thanks. Joe Athman =============================================================================This communication, together with any attachments hereto or links contained herein, is for the sole use of the intended recipient(s) and may contain information that is confidential or legally protected. If you are not the intended recipient, you are hereby notified that any review, disclosure, copying, dissemination, distribution or use of this communication is STRICTLY PROHIBITED. If you have received this communication in error, please notify the sender immediately by return e-mail message and delete the original and all copies of the communication, along with any attachments hereto or links herein, from your system. =============================================================================The St. Paul Travelers e-mail system made this annotation on 06/12/06, 10:52:07.
Just kind of shooting from the hip, but this *might* work: var func = myElement.onclick; func(); But it is Monday and I am tired :) Greg> -----Original Message----- > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org[mailto:rails-spinoffs-> bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Athman,Joseph J > Sent: Monday, June 12, 2006 8:52 AM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: [Rails-spinoffs] Cross Broswer Fire Event > > Is there a standard way of programmatically firing an event on an > element? I think this code works in IE but not FF: > > myElement.fireEvent(''onclick''); > > I really only care about IE and FF, but anything else is a bonus. I > didn''t see anything in prototype/scriptaculous for this, but I might > have missed it. Thanks. > > Joe Athman > >========================================================================> ===> This communication, together with any attachments hereto or links> contained herein, is for the sole use of the intended recipient(s) andmay> contain information that is confidential or legally protected. If youare> not the intended recipient, you are hereby notified that any review, > disclosure, copying, dissemination, distribution or use of this > communication is STRICTLY PROHIBITED. If you have received this > communication in error, please notify the sender immediately by returne-> mail message and delete the original and all copies of thecommunication,> along with any attachments hereto or links herein, from your system. > >========================================================================> ===> The St. Paul Travelers e-mail system made this annotation on 06/12/06,> 10:52:07. > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Gregory Hill wrote:> var func = myElement.onclick; > func();You can get rid of the temp variable: myElement.onclick(); Eric
But I like my temp variable :) Yeah, it''s Monday. Greg> -----Original Message----- > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org[mailto:rails-spinoffs-> bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Eric Anderson > Sent: Monday, June 12, 2006 8:59 AM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: [Rails-spinoffs] Re: Cross Broswer Fire Event > > Gregory Hill wrote: > > var func = myElement.onclick; > > func(); > > You can get rid of the temp variable: > > myElement.onclick(); > > Eric > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
That would only execute the function that is attached to the onclick event (if there is one), not actually cause the onclick event to fire. Also, if there was not function attached to the onclick event, that would cause an error. To actually fire the event and cause all event handlers to execute (whether they were attached inline or via the W3C model... use the event name (without the "on") as a function invocation... myElement.click(); ...I know this works for the click event, I''ve not tested it with the other events though. On 6/12/06, Eric Anderson <eric-ANzg6odk14w@public.gmane.org> wrote:> > Gregory Hill wrote: > > var func = myElement.onclick; > > func(); > > You can get rid of the temp variable: > > myElement.onclick(); > > Eric > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Sorry, I assumed he meant he wanted to call the function attached to the onclick. Your solution works with click events, but there is no ''mouseover()'' function :-) Anyway, as I mentioned, I am tired, and it is Monday, so I wasn''t really sure I was answering the question correctly (waiting for the Mountain Dew to kick in...). Also, doing myform.submit() does not fire the onsubmit handler (I''m sure there''s a good reason, but I dunno what it is), so it isn''t a universal solution. But, yeah, if he wanted to trigger the chain of click events, he''d need to call the click() function. Greg ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Monday, June 12, 2006 9:13 AM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails-spinoffs] Re: Cross Broswer Fire Event That would only execute the function that is attached to the onclick event (if there is one), not actually cause the onclick event to fire. Also, if there was not function attached to the onclick event, that would cause an error. To actually fire the event and cause all event handlers to execute (whether they were attached inline or via the W3C model... use the event name (without the "on") as a function invocation... myElement.click(); ...I know this works for the click event, I''ve not tested it with the other events though. On 6/12/06, Eric Anderson <eric-ANzg6odk14w@public.gmane.org> wrote: Gregory Hill wrote:> var func = myElement.onclick; > func();You can get rid of the temp variable: myElement.onclick(); Eric _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Ryan Gahl wrote:> That would only execute the function that is attached to the onclick > event (if there is one), not actually cause the onclick event to fire.Good point. I didn''t think about observers and other effects of event dispatching. In that case another thing to take a look at would be the unit testing library in script.aculo.us. It has some experimental functionality for simulating mouse events and key events: http://dev.rubyonrails.org/browser/spinoffs/scriptaculous/src/unittest.js?format=txt It''s right at the top of this file. Eric
Thanks for the help. That testing mouse simulation stuff seems pretty useful, does anyone know if they plan on putting it into scriptaculous? I appreciate it. Joe Athman -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Eric Anderson Sent: Monday, June 12, 2006 10:40 AM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] Re: Cross Broswer Fire Event Ryan Gahl wrote:> That would only execute the function that is attached to the onclick > event (if there is one), not actually cause the onclick event to fire.Good point. I didn''t think about observers and other effects of event dispatching. In that case another thing to take a look at would be the unit testing library in script.aculo.us. It has some experimental functionality for simulating mouse events and key events: http://dev.rubyonrails.org/browser/spinoffs/scriptaculous/src/unittest.j s?format=txt It''s right at the top of this file. Eric _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs =============================================================================This communication, together with any attachments hereto or links contained herein, is for the sole use of the intended recipient(s) and may contain information that is confidential or legally protected. If you are not the intended recipient, you are hereby notified that any review, disclosure, copying, dissemination, distribution or use of this communication is STRICTLY PROHIBITED. If you have received this communication in error, please notify the sender immediately by return e-mail message and delete the original and all copies of the communication, along with any attachments hereto or links herein, from your system. =============================================================================The St. Paul Travelers e-mail system made this annotation on 06/12/06, 11:48:30.
What about the onchange event? It doesn''t look like there is a element.change() function. Thoughts? Joe Athman -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Eric Anderson Sent: Monday, June 12, 2006 10:40 AM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] Re: Cross Broswer Fire Event Ryan Gahl wrote:> That would only execute the function that is attached to the onclick > event (if there is one), not actually cause the onclick event to fire.Good point. I didn''t think about observers and other effects of event dispatching. In that case another thing to take a look at would be the unit testing library in script.aculo.us. It has some experimental functionality for simulating mouse events and key events: http://dev.rubyonrails.org/browser/spinoffs/scriptaculous/src/unittest.j s?format=txt It''s right at the top of this file. Eric _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs =============================================================================This communication, together with any attachments hereto or links contained herein, is for the sole use of the intended recipient(s) and may contain information that is confidential or legally protected. If you are not the intended recipient, you are hereby notified that any review, disclosure, copying, dissemination, distribution or use of this communication is STRICTLY PROHIBITED. If you have received this communication in error, please notify the sender immediately by return e-mail message and delete the original and all copies of the communication, along with any attachments hereto or links herein, from your system. =============================================================================The St. Paul Travelers e-mail system made this annotation on 06/12/06, 11:56:33.
This link may or may not help. http://www.quirksmode.org/js/introevents.html http://www.quirksmode.org/js/events_tradmod.html It''s a great discussion on JS events. And yes, element.fireEvent(''onclick''/etc) is IE 5.5+ centric. ~ Brice
I may have gotten this from Quirksmode. I''m not sure, but here is an example I use in a JSUnit test: //test with the onchange event var changeEvent = document.createEvent(''HTMLEvents''); changeEvent.initEvent( ''change'', true, true ); ti.value = ''4''; ti.dispatchEvent(changeEvent); Jamie ------------------------------ http://blog.dangdev.com On Jun 12, 2006, at 2:29 PM, Brice Burgess wrote:> This link may or may not help. > > http://www.quirksmode.org/js/introevents.html > http://www.quirksmode.org/js/events_tradmod.html > > It''s a great discussion on JS events. And yes, element.fireEvent > (''onclick''/etc) is IE 5.5+ centric. > > ~ Brice > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs