views:

396

answers:

3

I want to implement City and State auto suggest in a form textbox. How do I do this?

Weather.com has a great example on this on their front page.

Questions:

  1. Where can I find a complete USA listing of city and state pairings? And is there an open API for this?
  2. Do any existing scripts/frameworks exists that already perform this auto-suggest task of city+state for textboxes?
+1  A: 

try http://plugins.jquery.com/project/jq-autocomplete

http://en.wikipedia.org/wiki/List_of_United_States_cities_by_population or, how about this one? http://www.census.gov/popest/cities/SUB-EST2008-4.html

this is the oficial page of U.S. Census Bureau. You can parse the CSV.

Besides, you don't neeed AJAX if you have already the info in an array... but you have to fill it first.

You might wanna see this too

http://forums.asp.net/t/1373395.aspx

Gmi182
I combined all your answers together. Please use the edit link rather than posting 4 "answers"..
Jeff Atwood
thanks, but i'm new and the system doesn't allow me to post more than 1 link in a comment
Gmi182
+1  A: 

If you're looking for a nice database of world cities with population > 1000, check out the geonames.org database. They have a sql dump available. Among other things, you'll also get countries, regions, and latitude/longitude from this database.

In general, the search term that might be helpful to you if you're getting your feet wet is GIS (geographic information systems).

Koobz
A: 

Rather than maintaining your own database, I'd suggest you check out the Freebase Suggest plugin for jQuery. See this similar question.

That plugin will do all the auto-completion and even the suggestion UI for you (you just point it to a text box) and you can specify that you just want to auto-complete locations (or only US counties, or whatever). It might be a little US-centric, but it sounds like that will work for your particular use case.

npdoty