toggling a DIV based on a menu selection

I have a situation where when the user selects a state for a model by
choosing a particular menu item in the view, I want to either show or
hide a DIV containing other relevant attribute choices... pretty basic
stuff, but I'm still a newbie on a lot of the rails view/ui stuff.

I think I need a combination of observe_field on the attribute being
changed by the menu and then some kind of Prototype toggle effect. And
I also need to check the match the user's menu choice against a
condition that says whether or not to show the secondary set of
choices in the DIV.

Can anyone show me what the code fragment would look like to do this?



how about

In the view:

<div id='test_div'>
  this is the text to hide
Click toggle to hide the text:
<%= link_to_remote "Toggle", :url=>{:action=>:toggle} %>

In the controller:

def toggle
  render :update do |page|
     page.hide 'test_div'

That is very simplistice but it may get you started. If you want to
toggle both ways then you need to be a bit smarter. From your
description, I suspect you actually want a drop down select box. So
you will need to use observe field to call a method that will check
the selected value and render hide or show accordingly.



Whoa, no need for a round-trip to the server just to toggle a div.
This will do the toggle on the client side:

<%= link_to_function 'Toggle', 'Element.toggle("test_div")' %>

Element.toggle is a Prototype function.

Indeed. I failed to read the OP carefully. Thanks.