# Dependency within form

**URL:** <https://www.ruby-forum.com/t/dependency-within-form/185109>\
**Category:** Rails\
**Created:** [March 13, 2010, 10:35pm UTC](https://www.ruby-forum.com/t/dependency-within-form/185109 "2010-03-13T22:35:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dudebot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Dudebot](https://www.ruby-forum.com/u/Dudebot)\
**Post date:** [March 13, 2010, 10:35pm UTC](https://www.ruby-forum.com/t/dependency-within-form/185109/1 "2010-03-13T22:35:15Z")

</div>

Is there any way to have one drop-down collection dependent on another  
within a form? E.g.

\<% form\_for @lab, :html =\> { :multipart =\> true } do |f| %\>

 \<%= f.collection\_select :lab\_desc\_id, LabDesc.find\_main, :id, :name %\> \<%= f.collection\_select :unit\_id, LabDesc.units( ??? ), :id, :units %\> \<% end %\>

So that ??? “knows” the id that was chosen in the first  
collection\_select?

Many TIA,  
Craig

---

<div class="post-metadata">

**Author:** ![Dudebot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Dudebot](https://www.ruby-forum.com/u/Dudebot)\
**Post date:** [March 15, 2010, 2:29pm UTC](https://www.ruby-forum.com/t/dependency-within-form/185109/2 "2010-03-15T14:29:07Z")

</div>

Dudebot wrote:

> Is there any way to have one drop-down collection dependent on another  
> within a form? E.g.
> 
> \<% form\_for @lab, :html =\> { :multipart =\> true } do |f| %\>
> 
> \<%= f.collection\_select :lab\_desc\_id, LabDesc.find\_main, :id, :name %\> \<%= f.collection\_select :unit\_id, LabDesc.units( ??? ), :id, :units %\> \<% end %\>
> 
> So that ??? “knows” the id that was chosen in the first  
> collection\_select?
> 
> Many TIA,  
> Craig

I’m pretty sure that the last time this question was asked, the answer  
was “Javascript”. Let the answer to the first one do an AJAX load of the  
second one.
