Jim Burgess
2009-May-30 09:10 UTC
Is there a rails equivalent of <body onload="do_stuff()">
Hi, I want to call a javascript function after my page has loaded. Currently I am using: <body onload="do_stuff()"> Is there a neater / tidier way to do this using any rails specific commands? I found this: document.observe(''dom:loaded'', function() { $(''state_field'').hide(); $(''person_country_id'').observe(''change'', countrySelected); }); which is part of a tutorial for creating dynamic drop down menus, but when I, for example, try: document.observe(''dom:loaded'', function() { alert(''hello''); }); this has no effect, rather it is output as html, as though I had witten <p>document.observe(''dom:loaded'', function() {alert(''hello'');});</p> Grateful for any help. -- Posted via http://www.ruby-forum.com/.
Jim Burgess
2009-May-30 09:12 UTC
Re: Is there a rails equivalent of <body onload="do_stuff()">
Sorry, I forgot the <script> tags. Now eveything works. Forget I spoke :-) -- Posted via http://www.ruby-forum.com/.
Marnen Laibow-Koser
2009-May-30 13:12 UTC
Re: Is there a rails equivalent of <body onload="do_stuff()">
Jim Burgess wrote:> Sorry, I forgot the <script> tags. > Now eveything works.Excellent! Now take the JS out of the HTML and put it in an external file. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
Jim Burgess
2009-May-30 13:23 UTC
Re: Is there a rails equivalent of <body onload="do_stuff()">
> Excellent! Now take the JS out of the HTML and put it in an external > file.Cool, that works. Thanks a lot. -- Posted via http://www.ruby-forum.com/.
Rick DeNatale
2009-May-30 16:13 UTC
Re: Is there a rails equivalent of <body onload="do_stuff()">
On Sat, May 30, 2009 at 9:23 AM, Jim Burgess <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> >> Excellent! Now take the JS out of the HTML and put it in an external >> file. > > Cool, that works. > Thanks a lot. > --You might want to have a look at Low Pro http://www.danwebb.net/2006/9/3/low-pro-unobtrusive-scripting-for-prototype It was built for prototype, but there''s a version for use with jquery as well http://www.danwebb.net/2008/2/3/how-to-use-low-pro-for-jquery Although I haven''t used that. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale