Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto filling a Zip Code Text box Based on selected state 1

Status
Not open for further replies.

asphyx9

IS-IT--Management
Jul 31, 2003
7
US
Hello,

I am writing a simple form application that submits to a database. I have database filled select box of cities, and a text box for a corresponding zip code (which can be database filled as well). How would I fill in the Zip Code text box automatically based on the selected state? I would like to do this without making a roundtrip to the server, and I welcome any client-side suggestions.

Thanks!
 
kinda messy doing it upsidedown like that, states have more than one zip code, and by basing your zip field off a state is kinda ugly, doing city and state from zip is a much better outlook, and unfortunately, i wouldn't know what to tell you with the hopes of accuracy in your requested instance.
 
I made a mistake in my post, I meant based on selected city! Sorry about that. It would be messy to do that by state indeed DreXor!
 
even by mediocre sized city there will still be on avg about 4-6 zip codes, granted you can select these 4-6 zips from the DB and put them in a drop down for selection, but at this point yuou've made the user enter : City,State, now Select Zip
vs :
Enter zip, Verify city/state ( prefilled text )

if you'd like help with either of those options i'd be happy to explain more.

 
The Cities that I am dealing with have only 1 zip code (My client is located in Rural Central Washington, so the cities that they service only have one zip code - they provided me with a list).

Help with the second option you presented (enter zip code, and verify City/State Autofill would be the one I would like help on). Thanks!
 
if you have a table already established, that has zip codes cities and states, then you just need to do a simple

select Top 1 * from reftable where zip='<enteredZip>'

if you dont have one of these tables, then next easiest form of this kind of table would be ... your client DB [purpleface] ...

select top 1 city,state from clientaddressing where zip='<entered zip>'

nice part about this second option is as you get more clients, you get more of a broad zip reference without having to update it.

add in :
<%
if RS.EOF then
response.write "Zip code not found please enter the City and State."
Else
response.write "Zip code found please Verify City and State to be correct."
City = RS("City")
State= RS("State")
End If
%>
<input type="text" maxlength="5" size="7" name="zip" value="<%=Request("Zip")%>">
<input type="text" name="City" value="<%=City%>">
<input type="text" name="State" maxlength="2" size="3" value="<%=State%>">

and so on :)
 
You could also take a look at this post: thread333-829358 the methods used in the various answers would be similar for you as well.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top