# 2 comboboxes

**URL:** <https://www.ruby-forum.com/t/2-comboboxes/116581>\
**Category:** Rails\
**Created:** [October 7, 2007, 3:47pm UTC](https://www.ruby-forum.com/t/2-comboboxes/116581 "2007-10-07T15:47:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![demoversion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4491bb/32.png) [@demoversion](https://www.ruby-forum.com/u/demoversion)\
**Post date:** [October 7, 2007, 3:47pm UTC](https://www.ruby-forum.com/t/2-comboboxes/116581/1 "2007-10-07T15:47:23Z")

</div>

Hello, I have a 2 comboboxes on my web-page. first contains list of  
cities, and other contains list of companies. But i need to filter  
second combobox by selected city in first combo.  
What the best way to implement this.  
I know this is not hard task but i don’t what to invent wheel.

Thanks

---

<div class="post-metadata">

**Author:** ![demoversion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4491bb/32.png) [@demoversion](https://www.ruby-forum.com/u/demoversion)\
**Post date:** [October 7, 2007, 5:50pm UTC](https://www.ruby-forum.com/t/2-comboboxes/116581/2 "2007-10-07T17:50:51Z")

</div>

I made a selection helper… I know, it’s ugly code so the others need  
not comment 😛

In my case it was States and Cities though. If you take some time to  
understand the code you’ll be able to use it as well.

Please see the following in order:  
1)

> **[helper: collection\_for\_select](http://railshacks.blogspot.com/2007/09/helper-collectionforselect.html)**
>
> I didn't find the form helper that made collection select tags powerful enough, so I made my own. I don't know how to make a nice plugin ye...

2) [Parked at Loopia](http://pastie.caboo.se/104642)

In the pastie, you’ll see

1. state selection box in view → this would be your “city”
2. encodeURI\_selection helper → just a helper that it uses
3. show\_cities.rjs → this would be your “show\_companies.rjs” action
4. city\_select.rhtml → this would be your “company\_select.rjs”

Remember – your city is to my state, your company is to my city… so  
don’t get confused 🙂

On 10/7/07, Igor K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello, I have a 2 comboboxes on my web-page. first contains list of  
> cities, and other contains list of companies. But i need to filter  
> second combobox by selected city in first combo.  
> What the best way to implement this.  
> I know this is not hard task but i don’t what to invent wheel.
> 
> ## Thanks
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

–  
Ramon T.

---

<div class="post-metadata">

**Author:** ![demoversion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4491bb/32.png) [@demoversion](https://www.ruby-forum.com/u/demoversion)\
**Post date:** [October 7, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/2-comboboxes/116581/3 "2007-10-07T18:11:26Z")

</div>

Thanks Ramon, I’ll check it!
