I have a Javascript file that finds the top-left coordinates of an element (image) as follows: function getTopLeftCoordinate() { x=document.getElementById(''coordinate'').offsetLeft y=document.getElementById(''coordinate'').offsetTop alert (x) alert (y) } And, on "show.html.erb", I have the following: <p id="notice"><%= notice %></p> <p> <b> Name </b> <%= @dicom.name %> </p> <p> <b> Image </b> </p> <p> <%= image_tag @dicom.photo.url , :id => ''coordinate'' %> </p> <%= javascript_include_tag "coordinate" %> <%= link_to ''Edit'', edit_dicom_path(@dicom) %> <%= link_to ''Back'', dicoms_path %> As you know, if I want to run the Javascript code on loading the page, I use <body onload="getTopLeftCoordinate()";> How can I do that in my "show.html.erb" file? Since I don''t have a body tag? Thanks. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I used Tim Parkin''s post here: http://www.ruby-forum.com/topic/146295 Based on his solution, I had to do the following for it to work. In "show.html.erb": <%= update_page_tag do |page| page << "getTopLeftCoordinate();" end %> Thanks. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
what librery are you using? On Sun, Sep 12, 2010 at 7:18 PM, Abder-Rahman Ali <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> I used Tim Parkin''s post here: http://www.ruby-forum.com/topic/146295 > > Based on his solution, I had to do the following for it to work. > > In "show.html.erb": > > <%= update_page_tag do |page| > page << "getTopLeftCoordinate();" > end > %> > > Thanks. > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito wrote:> what librery are you using?What do you mean by the library here? I just used Javascript and included the Javascript in the view (show.html.erb). Does that make sense? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sep 12, 11:48 pm, Abder-Rahman Ali <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> As you know, if I want to run the Javascript code on loading the page, I > use <body onload="getTopLeftCoordinate()";> > > How can I do that in my "show.html.erb" file? Since I don''t have a body > tag? >If I were you I''d have a separate js file with something like document.observe(''dom:loaded'', ...) or $(document).ready that invokes your javascript Fred> Thanks. > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Sep 12, 11:48�pm, Abder-Rahman Ali <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> As you know, if I want to run the Javascript code on loading the page, I >> use <body onload="getTopLeftCoordinate()";> >> >> How can I do that in my "show.html.erb" file? Since I don''t have a body >> tag? >> > > If I were you I''d have a separate js file with something like > document.observe(''dom:loaded'', ...) or $(document).ready that invokes > your javascript >Agreed. <body onload> is risky as well as not being unobtrusive.> FredBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
You should use s javascript librery other wise it will take you ages to make something practical and even more time to make your code work on all browsers. javascript libreries lets you do thigns like client side validation, date picker, inline editing, autocomplete, slider, drag and drop, sorting tooltips, progress bar ajax. In other words make your site fell like a desktop application http://jqueryui.com/ http://mootools.net/ http://www.dojotoolkit.org/ On Mon, Sep 13, 2010 at 9:38 AM, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> Frederick Cheung wrote: > > On Sep 12, 11:48�pm, Abder-Rahman Ali <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > >> As you know, if I want to run the Javascript code on loading the page, I > >> use <body onload="getTopLeftCoordinate()";> > >> > >> How can I do that in my "show.html.erb" file? Since I don''t have a body > >> tag? > >> > > > > If I were you I''d have a separate js file with something like > > document.observe(''dom:loaded'', ...) or $(document).ready that invokes > > your javascript > > > > Agreed. <body onload> is risky as well as not being unobtrusive. > > > Fred > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks a lot everyone. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.