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 <[email protected]>
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to