I have a form set up in asp using Dreamweaver with a text box for Zip, City, and State. I want a person to fill in zip and then when they move to the next field to have it fill in city and state. I also have a database called zipcodes and a table called zip with zip, city, state fields. Can anyone tell me how to do this. I have tried so many different things and just can't get it to work.

I have a form set up in asp using Dreamweaver with a text box for Zip, City, and State. I want a person to fill in zip and then when they move to the next field to have it fill in city and state. I also have a database called zipcodes and a table called zip with zip, city, state fields. Can anyone tell me how to do this. I have tried so many different things and just can't get it to work.

Hi ! I am new to it too.... so i am not sure , if i'll really be able to help you out.. but here's what i can make of it...

you can store the zip in a variable by
strzip =<%form.request("zip") %> where zip is the name of the text box which gets the zip value

next you create a connection object
and then you create the record set

<%dim recordset1
set recordset1 = Server.CreateObject("ADODB.RecordSet")
recordset1.open "zipcodes" , <connection string>

' now we use the filter collection to filter the recordset according to your pin

recordset1.filter = " zip = strzip " %>

'here zip is the field in the table

<input type = "text" value =<%response.write("recordset1.fields("city")" name="text1")

<input type = "text" value =<%response.write("recordset1.fields("state")" name="text2")

<%recordset1.close
set recordset1 = nothing %>


I hope it helps... let me know ..

Hi ! I am new to it too.... so i am not sure , if i'll really be able to help you out.. but here's what i can make of it...

you can store the zip in a variable by
strzip =<%form.request("zip") %> where zip is the name of the text box which gets the zip value

next you create a connection object
and then you create the record set

<%dim recordset1
set recordset1 = Server.CreateObject("ADODB.RecordSet")
recordset1.open "zipcodes" , <connection string>

' now we use the filter collection to filter the recordset according to your pin

recordset1.filter = " zip = strzip " %>

'here zip is the field in the table

<input type = "text" value =<%response.write("recordset1.fields("city")" name="text1")

<input type = "text" value =<%response.write("recordset1.fields("state")" name="text2")

<%recordset1.close
set recordset1 = nothing %>


I hope it helps... let me know ..

i dont' think this would work..since we need a way to post the values back to the form...
somebody else plz help..

there are 2 ways to do it.

1. Ajax- through which you can make server request without refreshing the page.

2. on page load, store all the values in a string variable as

str = "zip,state,country|zip,state,country|zip,state,country"

then when user enters zip code, the using client side script, you can filter out the values for this zip code and fill the state and country fields.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.