# Dynamically showing data based on different selection

**URL:** <https://www.ruby-forum.com/t/dynamically-showing-data-based-on-different-selection/106480>\
**Category:** Rails\
**Created:** [June 11, 2007, 4:30am UTC](https://www.ruby-forum.com/t/dynamically-showing-data-based-on-different-selection/106480 "2007-06-11T04:30:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![surfman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/49beb7/32.png) [@surfman](https://www.ruby-forum.com/u/surfman)\
**Post date:** [June 11, 2007, 4:30am UTC](https://www.ruby-forum.com/t/dynamically-showing-data-based-on-different-selection/106480/1 "2007-06-11T04:30:51Z")

</div>

suppose there is a selection list that has different selections, I want  
to show different items to my users based on each different selection.

say, there is selection list that has breakfast, lunch, dinner, when a  
user chooses breakfast, the page will show all items for breakfast, for  
instance, bread, milk, sausage, when the user chooses lunch, the same  
page will show beef, soup, noodles, etc.

is there any fast way to do this? thanks.

---

<div class="post-metadata">

**Author:** ![surfman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/49beb7/32.png) [@surfman](https://www.ruby-forum.com/u/surfman)\
**Post date:** [June 11, 2007, 7:35am UTC](https://www.ruby-forum.com/t/dynamically-showing-data-based-on-different-selection/106480/2 "2007-06-11T07:35:53Z")

</div>

I have the same situation where the users selects a room, then  
storage , then sub compartment each with it’s own unique dataset.  
[Room]/ [Storage type]/ [Sub storage]/ [Substorage]/

The storage model uses the “acts\_as\_tree” for hierarchy.

it’s a patch (if there is a better way to do it I’ll be glad to  
refactor it):

\<% if !storages.empty?%\>  
\<% type\_url = "’/storages/get\_selected\_type/’ +  
this[this.selectedIndex].value "%\>  
\<% select\_array = storages.collect {|storage| [ storage.type\_and\_name,  
storage.id ]}%\>  
\<%=select “storage”,“id”, select\_array,  
options = {:prompt =\> “- Select -”},  
html\_options={:onChange =\> "new Ajax.Request(#{type\_url},  
{ asynchronous:true,  
evalScripts:true ,  
onLoading:function(request){

Element.show(‘spinner\_storage’);  
Element.hide(‘storage\_children’); },  
onSuccess:function(request){

Element.hide(‘spinner\_storage’)})"}%\>  
\<%= spinner\_tag(“spinner\_storage”) %\>  
\<%else%\>  
selected  
\<%end%\>

I am creating an Ajax request on the change event, this calls returns  
the next selection dropdown.  
(p.s. the spinner tag is just an helper method to return a spinner).

Hope this helps.  
Jonathan Gross.  
removed\_email\_address@domain.invalid
