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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
Bill PrewIT / Software Engineering ConsultantCommented:
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.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.