This comes from this post on railsforum.
First, make sure you can do the basic javascript. See the pastie.
As you can see we are just going to use a basic toggle. Let’s keep things simple to start.
Now make sure you’re capable of doing a basic select box with selected working.
1 <%= f.label :redirect_locale, 'Page redirect:' %> 2 <%= select("page", "redirect_locale", { 3 "Yes, to posts. (works like a blog or news)" => 1, 4 "No. (keep as a normal page)" => 0, 5 }, { :selected => @page.redirect_locale })%>
1 <%= f.label :redirect_locale, ‘Page redirect:’ >
2 <= select("page", "redirect_locale", {
3 "Yes, to posts. (works like a blog or news)" => 1,
4 "No. (keep as a normal page)" => 0,
5 }, { :selected => @page.redirect_locale })%>
Now combine what you just did, but let’s use show and hide instead of toggle
1 <%= f.label :redirect_locale, 'Page redirect:' %> 2 <%= select("page", "redirect_locale", 3 {"Yes, to posts. (works like a blog or news)" => 1, "No. (keep as a normal page)" => 0,}, 4 { :selected => @page.redirect_locale }, 5 { :onchange => "if (this.value == '1') { $('body_toggle').hide(); $('sidebar_toggle').hide() } else { $('body_toggle').show(); $('sidebar_toggle').show(); }" })%>That should work as long as you have some divs or spans or p with the id=“sidebar_toggle” and id=“body_toggle”
![]()
Spitfire Sky | github | archives | resume