Roy Pardee
2009-Aug-20 21:45 UTC
Simple RJS question--toggling the text of a link_to_function link
Hey All, I''m dabbling in a little DHTML to show/hide a fieldset on a page, w/ the following: <% link_to_function("Show People", nil, :id => "more_link") do |page| page.visual_effect(:toggle_appear, "organization-people") page.replace_html("more_link", "Hide People") end %> This works very nicely, except for one thing--when the page loads, the link attached to the resulting jscript function is "Show People". The first time I click it changes to "Hide People" & the fieldset appears-- all very nice. My problem is that I don''t know how to change the link text back to "Show People" once the user clicks a second time. The link always *does* what I want--showing or hiding as appropriate, but it only *says* what I want for the first two clicks. Is there a way to find out what the current link contains so I can make that call to replace_html conditional? Many thanks! -Roy
Roy Pardee
2009-Aug-24 15:17 UTC
Re: Simple RJS question--toggling the text of a link_to_function link
Nobody has advice for me on this? :( On Aug 20, 2:45 pm, Roy Pardee <rpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey All, > > I''m dabbling in a little DHTML to show/hide a fieldset on a page, w/ > the following: > > <%> link_to_function("Show People", nil, :id => "more_link") do |page| > page.visual_effect(:toggle_appear, "organization-people") > page.replace_html("more_link", "Hide People") > end > %> > > This works very nicely, except for one thing--when the page loads, the > link attached to the resulting jscript function is "Show People". The > first time I click it changes to "Hide People" & the fieldset appears-- > all very nice. My problem is that I don''t know how to change the link > text back to "Show People" once the user clicks a second time. The > link always *does* what I want--showing or hiding as appropriate, but > it only *says* what I want for the first two clicks. > > Is there a way to find out what the current link contains so I can > make that call to replace_html conditional? > > Many thanks! > > -Roy
bill walton
2009-Aug-24 16:51 UTC
Re: Simple RJS question--toggling the text of a link_to_function link
Hi Roy, You should post your javascript function if you want help with modifying it. That''s where the modification of the link text would ''normally'' happen. Best regards, Bill On Mon, 2009-08-24 at 08:17 -0700, Roy Pardee wrote:> Nobody has advice for me on this? :( > > On Aug 20, 2:45 pm, Roy Pardee <rpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hey All, > > > > I''m dabbling in a little DHTML to show/hide a fieldset on a page, w/ > > the following: > > > > <%> > link_to_function("Show People", nil, :id => "more_link") do |page| > > page.visual_effect(:toggle_appear, "organization-people") > > page.replace_html("more_link", "Hide People") > > end > > %> > > > > This works very nicely, except for one thing--when the page loads, the > > link attached to the resulting jscript function is "Show People". The > > first time I click it changes to "Hide People" & the fieldset appears-- > > all very nice. My problem is that I don''t know how to change the link > > text back to "Show People" once the user clicks a second time. The > > link always *does* what I want--showing or hiding as appropriate, but > > it only *says* what I want for the first two clicks. > > > > Is there a way to find out what the current link contains so I can > > make that call to replace_html conditional? > > > > Many thanks! > > > > -Roy > >
Frederick Cheung
2009-Aug-24 17:00 UTC
Re: Simple RJS question--toggling the text of a link_to_function link
On Aug 24, 4:17 pm, Roy Pardee <rpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Nobody has advice for me on this? :( >you basically need to write some raw javascript for this ( if (''something''.innerHTML == ..)) and either mash that together with the rjs stuff using << or just write the whole thing in javascript and forget about the rjs bits Fred> On Aug 20, 2:45 pm, Roy Pardee <rpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hey All, > > > I''m dabbling in a little DHTML to show/hide a fieldset on a page, w/ > > the following: > > > <%> > link_to_function("Show People", nil, :id => "more_link") do |page| > > page.visual_effect(:toggle_appear, "organization-people") > > page.replace_html("more_link", "Hide People") > > end > > %> > > > This works very nicely, except for one thing--when the page loads, the > > link attached to the resulting jscript function is "Show People". The > > first time I click it changes to "Hide People" & the fieldset appears-- > > all very nice. My problem is that I don''t know how to change the link > > text back to "Show People" once the user clicks a second time. The > > link always *does* what I want--showing or hiding as appropriate, but > > it only *says* what I want for the first two clicks. > > > Is there a way to find out what the current link contains so I can > > make that call to replace_html conditional? > > > Many thanks! > > > -Roy
Roy Pardee
2009-Aug-25 12:33 UTC
Re: Simple RJS question--toggling the text of a link_to_function link
You mean I would have to sacrifice my carefully crafted complete ignorance of javascript? Bummer. ;-) Thanks guys. Perhaps today *is* a good day to start reading up on javascript. Thanks! -Roy On Aug 24, 10:00 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Aug 24, 4:17 pm, Roy Pardee <rpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Nobody has advice for me on this? :( > > you basically need to write some raw javascript for this ( if > (''something''.innerHTML == ..)) and either mash that together with the > rjs stuff using << or just write the whole thing in javascript and > forget about the rjs bits > > Fred > > > On Aug 20, 2:45 pm, Roy Pardee <rpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hey All, > > > > I''m dabbling in a little DHTML to show/hide a fieldset on a page, w/ > > > the following: > > > > <%> > > link_to_function("Show People", nil, :id => "more_link") do |page| > > > page.visual_effect(:toggle_appear, "organization-people") > > > page.replace_html("more_link", "Hide People") > > > end > > > %> > > > > This works very nicely, except for one thing--when the page loads, the > > > link attached to the resulting jscript function is "Show People". The > > > first time I click it changes to "Hide People" & the fieldset appears-- > > > all very nice. My problem is that I don''t know how to change the link > > > text back to "Show People" once the user clicks a second time. The > > > link always *does* what I want--showing or hiding as appropriate, but > > > it only *says* what I want for the first two clicks. > > > > Is there a way to find out what the current link contains so I can > > > make that call to replace_html conditional? > > > > Many thanks! > > > > -Roy