最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I implement auto-complete for CityState fields on a form? - Stack Overflow

programmeradmin3浏览0评论

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

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

Questions:

  1. Where can I find a plete 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?

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

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

Questions:

  1. Where can I find a plete 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?
Share Improve this question edited Feb 10, 2010 at 2:26 BillK asked Feb 10, 2010 at 2:08 BillKBillK 3911 gold badge4 silver badges5 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

If you're looking for a nice database of world cities with population > 1000, check out the geonames 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).

try http://plugins.jquery./project/jq-autoplete

http://en.wikipedia/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/t/1373395.aspx

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-pletion 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-plete 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.

发布评论

评论列表(0)

  1. 暂无评论