homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / WebmasterWorld / Webmaster General
Forum Library, Charter, Moderators: phranque

Webmaster General Forum

How to populate the city state field based on zip code
Jay Wilson Jr

 1:50 am on Apr 14, 2010 (gmt 0)

I'm trying to find out how to make teh city and state fields pre populate based off the zip code a user enters.

Can you point me in the right direction?





 8:10 am on Apr 14, 2010 (gmt 0)

Welcome to WebmasterWorld Jay Wilson Jr.

Most ZIP code databases include that information. Do you have a ZIP code database to work with?

Then it would depend on what type of technology you were using for your site.

Jay Wilson Jr

 8:21 am on Apr 14, 2010 (gmt 0)

Thank you for the welcome...

No I do not have a database. Can you recommend one?




 4:15 am on Apr 15, 2010 (gmt 0)

I believe the US Post Office offers them.


 10:28 pm on Apr 15, 2010 (gmt 0)

This is going to take some programming, of course. And it might not be worth it.

Also, think about this...

You know how you ask people twice to enter say, their password? People get it wrong. It's a good check to ask for this backup.

Even if you're not mailing them anything, but building a db, it's a good check to enhance the info's accuracy.

Now, if you are going to be mailing people stuff, you need to check out the USPS database where they'll make labels for you and such. A better investment would be to create an interface with their program.

Drill down deep into the postal service's web site for businesses that mail. And, of course, check out the other shippers web sites as well.


 5:21 am on Apr 16, 2010 (gmt 0)

USPS does offer their raw database on CD at a cost. I think $1,000 a year, but I'm not sure about that. You'd need to be able to convert it to SQL or something, and if you're good with databases it's fun and powerful to work with. It will let you convert zip codes to cities and vice-versa, and validate complete addresses down to the apartment number and Zip+4.

Jay Wilson Jr

 5:47 am on Apr 16, 2010 (gmt 0)

Thank you guys for the great input!

I have this working now. The USPS zip database is a great resource. Thanks for pointing me towards it.



 1:46 pm on Apr 17, 2010 (gmt 0)

I thought zip codes were public domain in the USA?

(In the UK the Royal Mail holds ownership of them.)

Jay Wilson Jr

 4:46 pm on Apr 17, 2010 (gmt 0)

In doing my research I found lots of Free zip databases....

I also found some paid databases as well. It would be my guess that the database complied by the USPS would be most accurate, I am not sure if zips are public domain or not...

If they are then, of course anyone could package them up and sell them under certain guidelines.



 4:51 pm on Apr 17, 2010 (gmt 0)

Be aware that some towns share a zip code. The wrong town name may come up.

Jay Wilson Jr

 4:54 pm on Apr 17, 2010 (gmt 0)

I noticed that...

I made it so that the field is editable, so the user can change it if need be. I am not shipping anything to the address at this time. If it ends up being a issue I will remove the autofill...

I am hoping my having it my cart abandon rate will lower.



 4:56 pm on Apr 17, 2010 (gmt 0)

zip codes used to be a service mark. they are not "public domain", they are an identification of a private corporation and are OPTIONAL in the united states: see Domestic Mail Services Regulations, Section 122.32. They should only apply to the places that fall under the jurisdiction of the District of Columbia.

As far as my limited knowledge of the subject goes, US has 2 separate laws, and 2 separate jurisdictions - State and Federal. There are people who fall under one and not under the other. People who do not fall under the "Federal" commercial law, will use addresses without a zip code.

A Postal Service is "quasi-government" agency, i.e. a private corporation, just like Federal Reserve. Zip Code™ does not apply to addresses that fall under the jurisdiction of a State only - as in 50 states of the union, excluding District Columbia, Puerto Rico, Guam and a couple of other territories.


 10:54 pm on Apr 17, 2010 (gmt 0)

I suggest being careful about using free zipcode databases, since ZIP codes *do* change over time - using free ones may open you up to stale/incorrect data.


 4:19 pm on Apr 18, 2010 (gmt 0)

Just my 2 cents, but when I abandon a cart, it is not because I have to type in my state and city. It is usually because I have cold feet about spending the money, or I discover shipping costs are too high, or I decide to shop around for a better price.

I applaud you efforts to make the process more seamless, but I think you should also examine some other areas if you are having cart abandonment issues.


 5:07 pm on Apr 18, 2010 (gmt 0)

I use one for my events sites, but I run into problems because physical addresses aren't necessarily the same as mailing addresses. Thinking of unhooking it.

I agree with maximillianos though - I don't think it will likely do too much to improve your cart issues. In my experience, shipping costs and lack of a "one button" order process contribute the most.

Jay Wilson Jr

 6:55 pm on Apr 18, 2010 (gmt 0)

You may be right - we are split testing this order form against the control. In a few days we will have some solid metrics.

Thanks for the great feedback,



 1:51 am on Apr 19, 2010 (gmt 0)

You can find lots of free zip code databases, just look around, it's all there for free.

If you don't know much about databases and you only use this database like once per member, so it's not getting hit alot, it requires almost NO programming to get the data you need almost instantly.

Forget importing to a database and all that mess, download a CSV or fixed width record format file and access it redneck programmer style.

You can execute a shell command to "GREP" the raw data file and it spits out a record in a fraction of a second.

So something like this will get your data:

grep "95501" -i zipdatabase > temp0124

Read the content of temp0124 for the results.


 2:30 pm on Apr 19, 2010 (gmt 0)

Its all done for you!

I would go for geocode services



Global Options:
 top home search open messages active posts  

Home / Forums Index / WebmasterWorld / Webmaster General
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved