# Help needed on Select Form

**URL:** <https://www.ruby-forum.com/t/help-needed-on-select-form/186284>\
**Category:** Rails\
**Created:** [April 3, 2010, 6:07pm UTC](https://www.ruby-forum.com/t/help-needed-on-select-form/186284 "2010-04-03T18:07:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruby\_noobie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/cab0a1/32.png) [@ruby\_noobie](https://www.ruby-forum.com/u/ruby_noobie)\
**Post date:** [April 3, 2010, 6:07pm UTC](https://www.ruby-forum.com/t/help-needed-on-select-form/186284/1 "2010-04-03T18:07:52Z")

</div>

Dear all,

I am pretty new to ruby on rails and I am supposed to create a form with  
a few drop down options. The first drop down option will affect the  
result in the data appearing in the drop down option for the second  
field. E.g. If user select mobile phone as their device, the next drop  
down will show the different OS of the phone such as Android, Symbian  
etc… and not OS of a computer.

Hope to receive replies/help on this.

Many Thanks in advance.

---

<div class="post-metadata">

**Author:** ![ruby\_noobie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/cab0a1/32.png) [@ruby\_noobie](https://www.ruby-forum.com/u/ruby_noobie)\
**Post date:** [April 3, 2010, 9:16pm UTC](https://www.ruby-forum.com/t/help-needed-on-select-form/186284/2 "2010-04-03T21:16:17Z")

</div>

Deb Liew wrote:

> Dear all,
> 
> I am pretty new to ruby on rails and I am supposed to create a form with  
> a few drop down options. The first drop down option will affect the  
> result in the data appearing in the drop down option for the second  
> field. E.g. If user select mobile phone as their device, the next drop  
> down will show the different OS of the phone such as Android, Symbian  
> etc… and not OS of a computer.
> 
> Hope to receive replies/help on this.
> 
> Many Thanks in advance.

Hi,

You can use OnChange on the First select Box and call a remote function  
like  
\<%= collection\_select :device, :id, @devices, :id , :name, {},  
{:onchange =\> remote\_function( :update =\> “operating\_system”, :url =\> {  
:controller =\> “devices”, :action =\> “get\_os”}, :position =\> “replace”,  
:with =\> “‘device\_id=’+this.value”) } %\>  
And have an element say div with id=“operating\_systems”

In devices controller,action get\_os  
Find out @os (params[:device\_id] will give you the device’s id from  
which i suppose you can get the list of OS for the device)

Have a partial called \_get\_os.html.erb which will have the select box  
for the OS  
\<%= collection\_select :os, :id, @os, :id , :name %\>

This is one of the many ways you can implement this functioanlity.Hope  
You find this useful.

---

<div class="post-metadata">

**Author:** ![ruby\_noobie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/cab0a1/32.png) [@ruby\_noobie](https://www.ruby-forum.com/u/ruby_noobie)\
**Post date:** [April 5, 2010, 8:27am UTC](https://www.ruby-forum.com/t/help-needed-on-select-form/186284/3 "2010-04-05T08:27:15Z")

</div>

Hi,

Thank you for your reply.

Can I assume the method you stated is used when the values are inside  
the database? Or does it work the same if it is not?

Thanks, once again.

Charanya N. wrote:

> Deb Liew wrote:
> 
> > Dear all,
> > 
> > I am pretty new to ruby on rails and I am supposed to create a form with  
> > a few drop down options. The first drop down option will affect the  
> > result in the data appearing in the drop down option for the second  
> > field. E.g. If user select mobile phone as their device, the next drop  
> > down will show the different OS of the phone such as Android, Symbian  
> > etc… and not OS of a computer.
> > 
> > Hope to receive replies/help on this.
> > 
> > Many Thanks in advance.
> 
> Hi,
> 
> You can use OnChange on the First select Box and call a remote function  
> like  
> \<%= collection\_select :device, :id, @devices, :id , :name, {},  
> {:onchange =\> remote\_function( :update =\> “operating\_system”, :url =\> {  
> :controller =\> “devices”, :action =\> “get\_os”}, :position =\> “replace”,  
> :with =\> “‘device\_id=’+this.value”) } %\>  
> And have an element say div with id=“operating\_systems”
> 
> In devices controller,action get\_os  
> Find out @os (params[:device\_id] will give you the device’s id from  
> which i suppose you can get the list of OS for the device)
> 
> Have a partial called \_get\_os.html.erb which will have the select box  
> for the OS  
> \<%= collection\_select :os, :id, @os, :id , :name %\>
> 
> This is one of the many ways you can implement this functioanlity.Hope  
> You find this useful.

---

<div class="post-metadata">

**Author:** ![ruby\_noobie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/cab0a1/32.png) [@ruby\_noobie](https://www.ruby-forum.com/u/ruby_noobie)\
**Post date:** [April 5, 2010, 11:33am UTC](https://www.ruby-forum.com/t/help-needed-on-select-form/186284/4 "2010-04-05T11:33:00Z")

</div>

Hi,

According to my consideration,  
You will need the databases to be filled.I assumed that You have a table  
called OS and Device.And Os and device tables are associated to each  
other like OS belongs to Device  
That is how from the device’s id we can get the list of OS for that  
device in @os in the controller.

Regards,  
Charanya N.

Deb Liew wrote:

> Hi,
> 
> Thank you for your reply.
> 
> Can I assume the method you stated is used when the values are inside  
> the database? Or does it work the same if it is not?
> 
> Thanks, once again.
> 
> Charanya N. wrote:
> 
> > Deb Liew wrote:
> > 
> > > Dear all,
> > > 
> > > I am pretty new to ruby on rails and I am supposed to create a form with  
> > > a few drop down options. The first drop down option will affect the  
> > > result in the data appearing in the drop down option for the second  
> > > field. E.g. If user select mobile phone as their device, the next drop  
> > > down will show the different OS of the phone such as Android, Symbian  
> > > etc… and not OS of a computer.
> > > 
> > > Hope to receive replies/help on this.
> > > 
> > > Many Thanks in advance.
> > 
> > Hi,
> > 
> > You can use OnChange on the First select Box and call a remote function  
> > like  
> > \<%= collection\_select :device, :id, @devices, :id , :name, {},  
> > {:onchange =\> remote\_function( :update =\> “operating\_system”, :url =\> {  
> > :controller =\> “devices”, :action =\> “get\_os”}, :position =\> “replace”,  
> > :with =\> “‘device\_id=’+this.value”) } %\>  
> > And have an element say div with id=“operating\_systems”
> > 
> > In devices controller,action get\_os  
> > Find out @os (params[:device\_id] will give you the device’s id from  
> > which i suppose you can get the list of OS for the device)
> > 
> > Have a partial called \_get\_os.html.erb which will have the select box  
> > for the OS  
> > \<%= collection\_select :os, :id, @os, :id , :name %\>
> > 
> > This is one of the many ways you can implement this functioanlity.Hope  
> > You find this useful.
