Hello, I want to trigger a "click" event on a tag. I only know the "id" of the tag, but it is necessary that the event be triggered from the given tag. Its not easily possible to just trigger the same thing directly due to how the event is implemented. regards, Lukas --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sounds like all you need to do is something like this: Event.observe($(id), "click", function() { /* put the function here */ }); Just make sure that the object which you''re observing exists before you call the above line. Oftentimes, all you need to do is this: Event.observe(window, "load", function() { Event.observe($(id), "click", function() { /* put the function here */ }); }); which makes sure the element is loaded since the observation doesn''t begin until the page is completed. Read the Event section of the API for more information ( http://prototypejs.org/api/event ). -- Dash -- lsmith wrote:> Hello, > > I want to trigger a "click" event on a tag. I only know the "id" of > the tag, but it is necessary that the event be triggered from the > given tag. Its not easily possible to just trigger the same thing > directly due to how the event is implemented. > > regards, > Lukas > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 Mar 25, 5:54 pm, David Dashifen Kees <dashi...-NT0ononE2K1Wk0Htik3J/w@public.gmane.org> wrote:> Sounds like all you need to do is something like this: > > Event.observe($(id), "click", function() { /* put the function here > */ });I think you misunderstood my question. I have a "click" observer on a tag registered already, but now I want to trigger the event via javascript (as in not by clicking on the tag with the attached observer). Yes, what I am asking for sounds pretty hacky, but I do not want to rewrite tons of js I did not write myself to begin with, so I am willing to cut a corner here. regards, Lukas --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey, lsmith a écrit :> Yes, what I am asking for sounds pretty hacky, but I do not want to > rewrite tons of js I did not write myself to begin with, so I am > willing to cut a corner here.Simulating events is a very tricky thing. There''s no standard API for it yet. Thomas Fuchs simulates those for unit testing purposes, but that''s still highly experimental, and FF only. Look at his unittest.js file, the Event.simulateMouse stuff, and how he uses it in his unit/functional test pages. Still, probably not portable at all. So YMMV, big time. -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 Mar 25, 8:56 pm, Christophe Porteneuve <t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> Simulating events is a very tricky thing. There''s no standard API for > it yet. Thomas Fuchs simulates those for unit testing purposes, but > that''s still highly experimental, and FF only. Look at his unittest.js > file, the Event.simulateMouse stuff, and how he uses it in his > unit/functional test pages.Yeah, I was poking around there a bit, but then decided that it was not so much code I needed to modify to make it work slightly cleaner without having to simulate the event. Thanks for the feedback, good to know that I was on on the right track but figured out soon enough that it was heading towards a deadend :) regards, Lukas --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yeah, I misunderstood. Sorry :) -- Dash -- lsmith wrote:> On Mar 25, 5:54 pm, David Dashifen Kees <dashi...-NT0ononE2K1Wk0Htik3J/w@public.gmane.org> wrote: > >> Sounds like all you need to do is something like this: >> >> Event.observe($(id), "click", function() { /* put the function here >> */ }); >> > > I think you misunderstood my question. I have a "click" observer on a > tag registered already, but now I want to trigger the event via > javascript (as in not by clicking on the tag with the attached > observer). > > Yes, what I am asking for sounds pretty hacky, but I do not want to > rewrite tons of js I did not write myself to begin with, so I am > willing to cut a corner here. > > regards, > Lukas > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 Mar 26, 4:56 am, Christophe Porteneuve <t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> Hey, > > lsmith a écrit : > > > Yes, what I am asking for sounds pretty hacky, but I do not want to > > rewrite tons of js I did not write myself to begin with, so I am > > willing to cut a corner here. > > Simulating events is a very tricky thing. There''s no standard API for > it yet.There is, the W3C DOM 2 Events spec includes dispatchEvent for just this purpose: "dispatchEvent "This method allows the dispatch of events into the implementations event model. Events dispatched in this manner will have the same capturing and bubbling behavior as events dispatched directly by the implementation. The target of the event is the EventTarget on which dispatchEvent is called." <URL: http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget-dispatchEvent>The spec is unchanged since 2000, it''s a pity that the most common browser hasn''t implemented it.> Thomas Fuchs simulates those for unit testing purposes, but > that''s still highly experimental, and FF only. Look at his unittest.js > file, the Event.simulateMouse stuff, and how he uses it in his > unit/functional test pages.There''s an example of dispatchEvent on the Mozilla DOM pages: <URL: http://developer.mozilla.org/en/docs/DOM:element.dispatchEvent >> > Still, probably not portable at all. So YMMV, big time.IE has fireEvent, the following link may help: <URL: http://groups.google.com.au/group/comp.lang.javascript/browse_frm/thread/27e7c70e51ff8a99/98cea9cdf065a524?lnk=gst&q=dispatchEvent&rnum=2#98cea9cdf065a524>The link to fireEvent at MSDN in that thread is broken, but you can search for it. -- 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 -~----------~----~----~----~------~----~------~--~---
Hey Rob! RobG a écrit :> There is, the W3C DOM 2 Events spec includes dispatchEvent for just > this purpose:Yeah, sorry, I should have stated it clearer: there''s no *popularly implemented* standard API just yet.> The spec is unchanged since 2000, it''s a pity that the most common > browser hasn''t implemented it.Tell me about it! -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---