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
> 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 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 [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