# Population of drop down list contents from a prior drop down selection

**URL:** <https://www.ruby-forum.com/t/population-of-drop-down-list-contents-from-a-prior-drop-down-selection/123444>\
**Category:** Rails\
**Created:** [December 17, 2007, 8:07pm UTC](https://www.ruby-forum.com/t/population-of-drop-down-list-contents-from-a-prior-drop-down-selection/123444 "2007-12-17T20:07:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![crispy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e47774/32.png) [@crispy](https://www.ruby-forum.com/u/crispy)\
**Post date:** [December 17, 2007, 8:07pm UTC](https://www.ruby-forum.com/t/population-of-drop-down-list-contents-from-a-prior-drop-down-selection/123444/1 "2007-12-17T20:07:33Z")

</div>

Suppose you have two drop down selects that are related. The contents  
of both come from a database.You want the contents of the second one  
to be dependent on the selection made in the first one, but don’t want  
the user to have to hit SUBMIT to make the contents populate. For  
example, say the goal is to implement a role based access framework  
and the first drop down is the controllers available for a given  
right. Once the user selects a controller, you want the next drop  
down populated with only the actions available for that controller.

I suppose that this is an AJAX thing, but wasn’t sure how to do it.

Any suggestions?

---

<div class="post-metadata">

**Author:** ![crispy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e47774/32.png) [@crispy](https://www.ruby-forum.com/u/crispy)\
**Post date:** [December 17, 2007, 8:18pm UTC](https://www.ruby-forum.com/t/population-of-drop-down-list-contents-from-a-prior-drop-down-selection/123444/2 "2007-12-17T20:18:16Z")

</div>

the basic thing will be to place a form-submit in the onchange event of  
the selectbox.

if this calls an ajax or a full page reload is a question of taste. it  
would be faster, but is not absolutely necessary.

---

<div class="post-metadata">

**Author:** ![crispy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e47774/32.png) [@crispy](https://www.ruby-forum.com/u/crispy)\
**Post date:** [December 17, 2007, 8:21pm UTC](https://www.ruby-forum.com/t/population-of-drop-down-list-contents-from-a-prior-drop-down-selection/123444/3 "2007-12-17T20:21:04Z")

</div>

On Dec 17, 2007 1:06 PM, Crispy [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I suppose that this is an AJAX thing, but wasn’t sure how to do it.
> 
> Any suggestions?

RJS and partials. Replace the second drop down with a new version  
when the first drop down is changed.

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![crispy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e47774/32.png) [@crispy](https://www.ruby-forum.com/u/crispy)\
**Post date:** [December 17, 2007, 11:48pm UTC](https://www.ruby-forum.com/t/population-of-drop-down-list-contents-from-a-prior-drop-down-selection/123444/4 "2007-12-17T23:48:17Z")

</div>

I should warn you to replace the CONTENT of the second one, not the  
actual  
select box itself. I tried doing this in an app of mine and found out it  
wasn’t putting it through in the submit.

On Dec 18, 2007 5:50 AM, Greg D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > down populated with only the actions available for that controller.  
> > Greg D.  
> > [http://destiney.com/](http://destiney.com/)
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

---

<div class="post-metadata">

**Author:** ![crispy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e47774/32.png) [@crispy](https://www.ruby-forum.com/u/crispy)\
**Post date:** [December 18, 2007, 8:04pm UTC](https://www.ruby-forum.com/t/population-of-drop-down-list-contents-from-a-prior-drop-down-selection/123444/5 "2007-12-18T20:04:31Z")

</div>

Thorsten, keep in mind I’m new at this.  
How do you detect in Rails if the list box is changed? How do you  
take control at that point?

On Dec 17, 11:18 am, Thorsten M. \<rails-mailing-l…@andreas-
