Hi, In my view I currently have the following link which show/hides a div <%= link_to_function "Show Hide" do |page| page[:user_input_name].toggle end %> Instead of using a link to do the show/hiding I would like to use the onclick event of a checkbox. I understand that I can add javascript to the onclick event as follows: <%= form.check_box :io_1 ,{:onclick => "alert(''Testing'');"}%> However, is it possible to use rjs code in the onclick part of the form.check_box? I know that i can look at the view and grab the javascript generated by the link and explicitly paste that into the onclick part but I like using the RJS syntax. Is it possible? e.g. something like: <%= form.check_box :io_1 ,{:onclick => do |page| page[:user_input_name].toggle 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-/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 -~----------~----~----~----~------~----~------~--~---
On 30 Sep 2008, at 09:41, Tim Conner wrote:> > Hi, > In my view I currently have the following link which show/hides a div > <%= link_to_function "Show Hide" do |page| > page[:user_input_name].toggle > end %> > > Instead of using a link to do the show/hiding I would like to use the > onclick event of a checkbox. I understand that I can add javascript > to > the onclick event as follows: > <%= form.check_box :io_1 ,{:onclick => "alert(''Testing'');"}%> > > However, is it possible to use rjs code in the onclick part of the > form.check_box? > I know that i can look at the view and grab the javascript generated > by > the link and explicitly paste that into the onclick part but I like > using the RJS syntax. Is it possible? e.g. something like: > <%= form.check_box :io_1 ,{:onclick => do |page| > page[:user_input_name].toggle end }%> >That''s basically what update_page does. The name is a bit misleading, but basically it yields the same thing as you get in a render :update or the magic page object in a rjs file and returns the generated javascript. Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
sorry, so how do I use updaet_page in conjuction with a checkbox? The following doesn''t work: <%= form.check_box :io_1 , update_page{|page| page[:user_input_name].toggle}%> -- 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 -~----------~----~----~----~------~----~------~--~---
Apologies, I was being stupid. The correct way is: <%= form.check_box :io_1 , :onclick => update_page{|page| page[:user_input_name].toggle}%> Thanks for your help -- 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 -~----------~----~----~----~------~----~------~--~---