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?
Who is Participating?
Bill PrewCommented:
If you have a real business need then it might be worth it to subscribe / pay for a service that has solid availability and updated data, etc.

If you are just looking for a casual capability, here's a couple of potential references worth a look.

Eddie ShipmanAll-around developerCommented:
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,

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.
Jim RiddlesPrepress/OMS SpecialistCommented:
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.
Jim RiddlesPrepress/OMS SpecialistCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.