If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > dependant drop down boxes help?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-22-04, 00:00
zobernjik zobernjik is offline
Registered User
 
Join Date: Feb 2004
Location: Australia
Posts: 183
Unhappy dependant drop down boxes help?

Hello all,

I have a very simple web site used for sumbitting records on a daily basis, just to make the selection more clear I need to have a dependant drop down list and value of the first drop down would be described in the second according to their selection.

Here is an example that does exacltly what I need it to do but it refreshes which is a reall bugger for me since that wipes all other values entered in other fields.
I have been looking on the internet and there are many examples but still couldn't quite find what I really needed, have also read the best way to do this is so it doesn't refresh it by using javascript (not very good with Javascript).

So, clould this be changed so I get what I need and it doesn't refresh and if not how can do that.

<%
' Get the querystring for State and place it in a variable
v_state = request.querystring("State")

set conn = server.createobject("ADODB.Connection")
Conn.open("dsn=test;uid=sa;pwd=test;")
strSQL = "Select Distinct State from tblAddress Order by State"
set rectblAddress = conn.execute(strSQL)

' If there are no records found, display a message. Otherwise display our form.
if rectblAddress.eof then
response.write("No Addresses Found")
else
if v_State = "" then
v_State = rectblAddress("State")
end if
%>
<form method="POST" action="">
Product Code:

<select size="1" name="State" onChange="window.location='<%=request.servervariab les("Script_Name")%>?State='+this.value;">


<%do while not rectblAddress.eof
if rectblAddress("State") = v_State then
%>
<option selected value="<%=rectblAddress("State")%>"><%=rectblAddre ss("State")%></option>
<%
else
%>
<option value="<%=rectblAddress("State")%>"><%=rectblAddre ss("State")%></option>
<%
end if
rectblAddress.movenext
loop
rectblAddress.close
set rectblAddress = nothing
%>
</select>
&nbsp;&nbsp; Products:
<select size="1" name="City">
<%
' Here is where we are using the State value to select the correct cities to be shown.
strSQL = "Select Distinct City from tblAddress where State='" & v_State & "' Order by City"
set rectblAddress = conn.execute(strSQL)
do while not rectblAddress.eof
%>
<option value="<%=rectblAddress("City")%>"><%=rectblAddres s("City")%></option>
<%
rectblAddress.movenext
loop


%>
</select>

<p>&nbsp;</p>
</form>

<p>
<%

Hope somebody can help,thanks and regards
Reply With Quote
  #2 (permalink)  
Old 11-22-04, 16:58
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
You've got a few options, but none of them are simple, or easy to articulate. You could do it the refresh way as you mentioned, but that requires you to save all the other data every time a change is made.

You can use JavaScript, but that requires you to store all the values in JavaScript arrays, and if you're not good with JS, that will be a problem.

Lastly, you could do a combination of both. Create iframes that build select boxes from form parameters. When the first one on the main page is selected (onChange JS handler) you write some JS code to capture the value of the select box and save it to hidden variable of a hidden form who's action is to submit to the iframe of the next select box (through the target attribute), and so on down the line until you get to the last select box. The onChange of that last select box will call a JS function which copies the value back into a hidden variable of the parent form.

Ugly.. all of them are ugly...
__________________
That which does not kill me postpones the inevitable.
Reply With Quote
  #3 (permalink)  
Old 11-22-04, 19:47
zobernjik zobernjik is offline
Registered User
 
Join Date: Feb 2004
Location: Australia
Posts: 183
Smile

Thanks for your suggestions,

UGLY is the word here.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On