Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

zip code to city list

I have simple html form allow to enter zip code. my goal is if the user put 5 digital there, and it will populate
list of city in <div id=cityList></div>, and when <div> has value</div> then I can click on city, and populate the selected city
into another textbox <input type="text" id=city>

How can I do that in javascript?
Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

There are several ways to do this. Either have your own database of cities by zip code, use a 3rd party's database of cities by zip code, or get a developer API key from the USPS to do the lookup, https://www.usps.com/business/web-tools-apis/welcome.htm

Personally, I would rather use the one from the USPS because I don't have to keep the data updated and some 3rd party DB's are outdated now.
Understand that the USPS API is only to be used as part of a solution that uses the USPS Shipping service.  It is not intended to be used in the manner you are suggesting.

That said, if the author is intending to use the API is such a way, I have worked with this in the past to create a PHP solution that uses their API to verify addresses entered on our ordering site.  It is fairly easy to use.
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ZIP Code API offers this very service.  You can create a free account that allows up to 50 requests per hour, or sign up for an actual usage plan.

ZIP Code API Examples