Ax Plains
2007-Dec-03 09:59 UTC
How to remember if a div is shown or hidden after a page ref
Hi everyone, hi have a similar problem in a view: <div id="content">...</div> <a href="javascript:void(0)" onClick="Effect.Toggle(''content'');">Hide/show content</a> I would like the page to "remember" that the div has been hidden after a page reload. (The div comes up always visible even if it was set to hidden before). Any simple way to do this? Thanks a lot in advance -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Karthi kn
2007-Dec-03 11:30 UTC
Re: How to remember if a div is shown or hidden after a page
Ax Plains wrote:> Hi everyone, hi have a similar problem in a view: > > > <div id="content">...</div> > > <a href="javascript:void(0)" > onClick="Effect.Toggle(''content'');">Hide/show content</a> > > > I would like the page to "remember" that the div has been hidden after a > page reload. > (The div comes up always visible even if it was set to hidden before). > > Any simple way to do this? > Thanks a lot in advanceIf you are reloading the page in the controller, then you can use an instance variable in the controller to decide whether the div should be hidden or not.Like, In controller : @show_div_tag = true In view : <% default_style = @show_div_tag ? "" : "display:none" %> <div id="content" style="<%= default_style %>">...</div> You can also optimize this code. In case if you are manually reloading the browser, the above is applicable. Regards, - Karthi -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ax Plains
2007-Dec-03 13:08 UTC
Re: How to remember if a div is shown or hidden after a page
Karthi kn wrote:> Ax Plains wrote: >> Hi everyone, hi have a similar problem in a view: >> >> >> <div id="content">...</div> >> >> <a href="javascript:void(0)" >> onClick="Effect.Toggle(''content'');">Hide/show content</a> >> >> >> I would like the page to "remember" that the div has been hidden after a >> page reload. >> (The div comes up always visible even if it was set to hidden before). >> >> Any simple way to do this? >> Thanks a lot in advance > > If you are reloading the page in the controller, then you can use an > instance variable in the controller to decide whether the div should be > hidden or not.Like, > > In controller : > @show_div_tag = true > > In view : > <% default_style = @show_div_tag ? "" : "display:none" %> > > <div id="content" style="<%= default_style %>">...</div> > > You can also optimize this code. > > In case if you are manually reloading the browser, the above is > applicable. > > > Regards, > - KarthiThanks a lot. Anyway, I would like to let the user decide to let the div visible or not. I think the "show_div_tag" variable should be set when the user clicks on the link, and remembered between page refreshes (maybe in a session)? -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Karthi kn
2007-Dec-04 06:11 UTC
Re: How to remember if a div is shown or hidden after a page
Ax Plains wrote:> > Thanks a lot. > > Anyway, I would like to let the user decide to let the div visible or > not. > I think the "show_div_tag" variable should be set when the user clicks > on the link, and remembered between page refreshes (maybe in a session)?Yes. You can use the session also. if you are not using the session, you have to pass the current value of the variable to the controller for each call(by manually passing the value or by submitting in the form as a hidden value). -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ax Plains
2007-Dec-04 08:07 UTC
Re: How to remember if a div is shown or hidden after a page
Karthi kn wrote:> Ax Plains wrote: > >> >> Thanks a lot. >> >> Anyway, I would like to let the user decide to let the div visible or >> not. >> I think the "show_div_tag" variable should be set when the user clicks >> on the link, and remembered between page refreshes (maybe in a session)? > > Yes. You can use the session also. if you are not using the session, you > have to pass the current value of the variable to the controller for > each call(by manually passing the value or by submitting in the form as > a hidden value).Many thanks. In the end, I ended up using a cookie... works fine and does not confuse Ruby coding. Thanks a lot anyway. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---