Urgent Help with this script

S

sherif badr

Dear all:
i am in urgent need of help
in the following code i wnat to add a third combo box which it generates the
streets from the data base based on the selection of the first then the
second boxes
here is the code


<html>
<head>
<title>Multiple Dynamic Drop Down Boxes - ASP</title>
</head>
<body>
<%
' Get the querystring for State and place it in a variable
v_City = request.querystring("City")
v_District = request.querystring("District")

' Open Database and setup a recordset with States Listed.
' Note the Distinct option in the SQL statement. This will limit each state
to showing only once in the recordset.
set conn = server.createobject("ADODB.Connection")
Conn.Open "Data Source=" & Server.Mappath("fpdb/Settings.mdb") &
";Provider=Microsoft.Jet.OLEDB.4.0;"
strSQL = "Select Distinct City from District Order by City"
set rs = conn.execute(strSQL)

' If there are no records found, display a message. Otherwise display our
form.
if rs.eof then
response.write("No Addresses Found")
else
if v_City = "" then
v_City = rs("City")
end if
%>
<form method="POST" action="">
City
<!-- Here is the key to the whole thing. The onChange function is set to
refresh the page with the new State value.
For those who don't know, request.servervariables("Script_Name") will return
the name of your current page
You could of course hard code your page name rather than using the server
variable, I use this in the example
so that if it is copied to another page the script requires less modification.
-->
<select size="1" name="City"
onChange="window.location='<%=request.servervariables("Script_Name")%>?City='+this.value;">

<%do while not rs.eof
if rs("City") = v_City then
%>
<option selected value="<%=rs("City")%>"><%=rs("City")%></option>
<%
else
%>
<option value="<%=rs("City")%>"><%=rs("City")%></option>
<%
end if
rs.movenext
loop
rs.close
set rs = nothing
%>
</select>
District
<select size="1" name="District">
<%
' Here is where we are using the State value to select the correct cities to
be shown.
strSQL = "Select Distinct District from District where City='" & v_City & "'
Order by District"
set rs = conn.execute(strSQL)
do while not rs.eof
%>
<option value="<%=rs("District")%>"><%=rs("District")%></option>
<%
rs.movenext
loop
%>
</select>
<p><input type="submit" value="Submit" name="B1"><input type="reset"
value="Reset" name="B2"></p>
</form>
<%
end if
%>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top