1

I'm working on a rails app.

I have a dropdown with countries. Selecting a country would fill the city dropdown with the cities in that country.

I know how to do this server-side, but I'd like to do it client-side if possible. I've used the RJS helpers, but I've no experience with jQuery (not exactly even sure what it is) or the other selector javascript libraries.

Clarification: I'd like to do this entirely client-side. That is, send all the values in the initial page request. I'm not looking to call the server ajaxically, hit the database, then return those results. I'd like them loaded up with the page.

wesgarrison
  • 6,975
  • 5
  • 30
  • 39

4 Answers4

1

Maybe this can help (a simple google search did it):

http://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax/

Luca Matteis
  • 29,161
  • 19
  • 114
  • 169
  • This is for php, but should be almost identical for rails -- just the server side json generation would change. – Chris Hynes Feb 10 '09 at 02:52
  • Clarification: I'd like to do this **entirely** client-side. That is, send all the values in the initial page request. I'm not looking to call the server ajaxically, hit the database, then return those results. I'd like them loaded up with the page. [New to SO: is this the proper way to reply?] – wesgarrison Feb 11 '09 at 06:40
1

I used a combination of jQuery and the jQuery calculations plugin to get this working.

wesgarrison
  • 6,975
  • 5
  • 30
  • 39
0

I recommend you to use jQuery for this. But you need to take look documentation of jquery and then take a look jQuery ajax api

Barbaros Alp
  • 6,405
  • 8
  • 47
  • 61
-2

Creating a long list of elements with javascript will most likely perform worse on the client. Why would you prefer it?

Aram Verstegen
  • 2,407
  • 1
  • 17
  • 15
  • My list isn't that long, certainly nothing as long as a list of countries and all the cities in those countries. I'd like to avoid hitting the server to look up something that could be sent with the initial page request. – wesgarrison Feb 11 '09 at 06:29