hi all, I have 3 divs (with id) and according to a selection made in a selection box I want to show the corresponding div and hide the 2 other divs eg: selectionbox - car - bike - motor <div id="car"></div> <div id="bike"></div> <div id="motor"></div> So when car is selected div car should bes hown and the other 2 should be hidden. How can this best be done? Thanks Stijn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
plain old javascript. if you don''t know how to do it, google helps: http://www.webdeveloper.com/forum/showthread.php?t=122975 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Tarscher wrote:> So when car is selected div car should bes hown and the other 2 should > be hidden. > > How can this best be done? > > Thanks > StijnYou can do this using the Prototype library included as the default for Rails, or jQuery if you prefer that. 1. Attached an observer to the selection box after the DOM is ready Event.observe(window, ''load'', function() { $(''select_box'').observe(''change'', selectBoxHandler}); }); 2. Use AJAX to update the DOM function selectBoxHandler() { switch $F(''select_box'') { case ''car'': $(''car'').show(); $(''bike'').hide(); $(''motor'').hide(); break; case ''bike'': $(''bike'').show(); $(''car'').hide(); $(''motor'').hide(); case ''motor'': $(''motor'').show(); $(''car'').hide(); $(''bike'').hide(); break; } } Note: This is just "off-the-cuff" code, but is should show the gist of it. Also this can be accomplished using the Rails Prototype helpers, but I''ll leave that as an exercise for you. -- 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 -~----------~----~----~----~------~----~------~--~---
Thanks, that helped me a lot. I would like to set car as the default selection. I can use the :default => in options_for_select but that dooesn''t seem to trigger the observer. I tried to add Event.observe(window, ''load'', function() { $F(''game_type'').value = ''car'' }); after the selection box observer but it doesn''t set the car default. Someoene has an idea? Thanks On 20 feb, 15:13, Robert Walker <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Tarscherwrote: > > So when car is selected div car should bes hown and the other 2 should > > be hidden. > > > How can this best be done? > > > Thanks > > Stijn > > You can do this using the Prototype library included as the default for > Rails, or jQuery if you prefer that. > > 1. Attached an observer to the selection box after the DOM is ready > > Event.observe(window, ''load'', function() { > $(''select_box'').observe(''change'', selectBoxHandler}); > > }); > > 2. Use AJAX to update the DOM > > function selectBoxHandler() { > switch $F(''select_box'') { > case ''car'': > $(''car'').show(); > $(''bike'').hide(); > $(''motor'').hide(); > break; > case ''bike'': > $(''bike'').show(); > $(''car'').hide(); > $(''motor'').hide(); > case ''motor'': > $(''motor'').show(); > $(''car'').hide(); > $(''bike'').hide(); > break; > } > > } > > Note: This is just "off-the-cuff" code, but is should show the gist of > it. Also this can be accomplished using the Rails Prototype helpers, but > I''ll leave that as an exercise for you. > -- > 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-/JYPxA39Uh5TLH3MbocFFw@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 can try this also ....... <select name="timesheet[filter]" id="filter" onchange="if (value==''car'') {Element.show(''car'');Element.hide(''bike'');Element.hide(''motor'');} else {if {(value==''bike'') {Element.show(''bike'');Element.hide(''car'');Element.hide(''motor'');}else {Element.show(''motor'');Element.hide(''car'');Element.hide(''bike'');}}"}> <option value="car" >Car</option> <option value="bike" >Bike</option> <option value="motor" >Motor</option> </select> <div id="car">Showing Car</div> <div id="bike">Showing Bike</div> <div id="motor">Showing Motor</div> Regards, Salil -- 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 -~----------~----~----~----~------~----~------~--~---