Dynamic SelectBoxes/DropDownLists

Hi,

I’d like to implement in my project dynamic dropdown lists.
Example:
user will select one option from the parent dropdown list, lets say
it’ll be COUNTRY and in the child dropdown will be generated all CITIES
tied with this selected country.

I could then have relevant info in my form. Country and one of its city.

I know, this is not much abour RoR, however it has something to do w/
Ajax. I really like autocomplete feature in RoR and I’m sure this
dynamic dropdowns should be done easy in Ajax too.

any clues…?

thanks and have a great day

-> keli (milos kelemen)

milos kelemen wrote:>

I’d like to implement in my project dynamic dropdown lists.
Example:
user will select one option from the parent dropdown list, lets say
it’ll be COUNTRY and in the child dropdown will be generated all CITIES
tied with this selected country.

You could use an observe_field to monitor the choice in the first select
box, as in this example:
http://www.roryhansen.ca/?p=9

This is something I’m currently experimenting with myself - will let you
know how it goes.

Nick Ce wrote:

box, as in this example:
http://www.roryhansen.ca/?p=9

This is something I’m currently experimenting with myself - will let you
know how it goes.

tnak you nick,

I’ll let you know how it goes,

→ keli

Nick Ce wrote:

box, as in this example:
http://www.roryhansen.ca/?p=9

This is something I’m currently experimenting with myself - will let you
know how it goes.

Nick,

thanks for your help again…

this script works as it should

hi,
someone asked the exact same question here …see this
http://article.gmane.org/gmane.comp.lang.ruby.rails/32790/match=
and this
http://article.gmane.org/gmane.comp.lang.ruby.rails/33824/match=
Vivek

milos kelemen wrote:

Nick,

thanks for your help again…

this script works as it should

No problem - glad yours works ok - still having problems with mine :frowning:
I decided to go down the partials route as used in the posts that Vivek
linked to, here
http://article.gmane.org/gmane.comp.lang.ruby.rails/33824/match= and
here http://article.gmane.org/gmane.comp.lang.ruby.rails/33824/match=

At present I have this: http://www.rafb.net/paste/results/YxkO1V47.html

Unfortunately, when I make a choice on the first select, no content
appears within the person_list div - can anyone see anything wrong at
all?

Are you using Firefox? If so, make sure that the ID of the select box is
actually job_company_id. I’m not familiar with the output of
collection_select, but it may output only the NAME attribute and not the
ID
unless you explicitly tell it to.

In the post which I linked to…I didnt understand the use of :object …I
know of :collection which calls the template repeatedly…whats with this
:object ? does anyone here have an idea?

I saw rory’s solution… easier to follow…Thanks for the tip.
Vivek

Rory Hansen wrote:

Are you using Firefox? If so, make sure that the ID of the select box is
actually job_company_id. I’m not familiar with the output of
collection_select, but it may output only the NAME attribute and not the
ID unless you explicitly tell it to.

Thanks for the reply Rory. I’m actually using Camino, and the
collection_select generates this:

Client
company A company B

which looks ok to me.

Vivek wrote:

In the post which I linked to…I didnt understand the use of :object …I
know of :collection which calls the template repeatedly…whats with this
:object ? does anyone here have an idea?

From the Agile Rails book: “The :object parameter identifies an object
to be passed into the partial. This object will be available within the
template via a local variable with the same name as the template.” Not
sure I understand this fully - does my error lie with the naming of the
object variable perhaps? Still can’t get it to work as expected. The DIV
I’m trying to update is nested within a form; will that make any
difference? http://www.rafb.net/paste/results/YxkO1V47.html

Nick C wrote:

http://www.rafb.net/paste/results/YxkO1V47.html

Solved it - it was a syntax error - one measly single quote missing from
:with => “‘job_company_id=’+value”

The partial method in conjunction with collection_select certainly seems
a tidy way of doing dynamic drop downs.

Thanks to all those who chipped in.