# Countries -\> Cities Select box

**URL:** <https://www.ruby-forum.com/t/countries-cities-select-box/51726>\
**Category:** Rails\
**Created:** [January 6, 2006, 10:31am UTC](https://www.ruby-forum.com/t/countries-cities-select-box/51726 "2006-01-06T10:31:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vivek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/77aa72/32.png) [@vivek](https://www.ruby-forum.com/u/vivek)\
**Post date:** [January 6, 2006, 10:31am UTC](https://www.ruby-forum.com/t/countries-cities-select-box/51726/1 "2006-01-06T10:31:45Z")

</div>

I am trying to play with a Countries -\> Cities dynamically updating  
select  
box.that is if someone selects a country then all the cities of that  
country must be listed.Does anyone know of any data source for this?  
I searched for it but couldnt find any good usable source.  
Better still is there a module which I can mixin for this?  
Thanks  
Vivek

---

<div class="post-metadata">

**Author:** ![vivek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/77aa72/32.png) [@vivek](https://www.ruby-forum.com/u/vivek)\
**Post date:** [January 6, 2006, 2:41pm UTC](https://www.ruby-forum.com/t/countries-cities-select-box/51726/2 "2006-01-06T14:41:32Z")

</div>

you can do it the Ajax way…

[http://www.roryhansen.ca/?p=9](http://www.roryhansen.ca/?p=9)

---

<div class="post-metadata">

**Author:** ![vivek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/77aa72/32.png) [@vivek](https://www.ruby-forum.com/u/vivek)\
**Post date:** [January 6, 2006, 3:05pm UTC](https://www.ruby-forum.com/t/countries-cities-select-box/51726/3 "2006-01-06T15:05:02Z")

</div>

Chris H. wrote:

> you can do it the Ajax way…
> 
> [http://www.roryhansen.ca/?p=9](http://www.roryhansen.ca/?p=9)

The article uses Ajax to replace the entire SELECT element, since the  
author found it impossible to replace the innerHTML. I wonder if it  
might be possible to use RJS[1] for something like this, and have the  
ajax return javascript to repopulate the SELECT ?

Alan  
[1] [http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates](http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates)

---

<div class="post-metadata">

**Author:** ![vivek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/77aa72/32.png) [@vivek](https://www.ruby-forum.com/u/vivek)\
**Post date:** [January 8, 2006, 4:20am UTC](https://www.ruby-forum.com/t/countries-cities-select-box/51726/4 "2006-01-08T04:20:44Z")

</div>

Well Actually I got that part working. and Yes I had to replace the  
entire  
innerHTML including the select tag but then that was ok because other  
than a  
few countries for which I had an option of showing cities,I just wanted  
to  
show a blank text box. My only problem now is to figure out if there is  
anyway to do the ascyn ajax update only if the value is one of the  
countries  
i want to show a select option for. Because this results in unnecssary  
calls  
to the server.  
I guess I have to modify the generated javascript.  
Vivek
