|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I need help please. I have a an access db with 2 tables- subs and cats. I need two dropdown lists. when the page is loaded the CATS dropdown is populated. when i select a category from CATS i need the other dropdown to be filled with the corresponding categories. However, I am not sure how to do it. Can someone please help me? Thanks <%@ Language=VBScript %> <!--#include file="Connections/connDUclassified.asp" --> <% set rsCat = Server.CreateObject("ADODB.Recordset") rsCat.ActiveConnection = MM_connDUclassified_STRING rsCat.Source = "SELECT * FROM CATS ORDER BY CAT_DATED DESC" rsCat.CursorType = 0 rsCat.CursorLocation = 2 rsCat.LockType = 3 rsCat.Open() rsCat_numRows = 0 %> <!--I do an if statement to determine what browser people are using. If a person is using Internet Explorer this will load this version of the html page. Or below in the Else it will load a dropdown with a submit button. I de-test javascript and could have used client code to submit the form, but I'm prefer this way. It might not be the correct way but what the heck this is free code!--> <% If Instr(request.servervariables("http_user_agent"), "MSIE") Then %> <html> <head> <title>Demo Drop Down</title> </head> <body> <script language="vbscript"> sub submitthis 'document.write "change" form1.submit end sub </script> <p>Select from the dropdown menu</p><br> <form ACTION="" METHOD="POST" NAME="form1"> <p><select ONCHANGE="submitthis" SIZE="1" NAME="CAT_ID"> <% While (NOT rsCat.EOF) %> <option value="<%=(rsCat.Fields.Item("CAT_ID").Value)%>" <%if (CStr(rsCat.Fields.Item("CAT_ID").Value) = CStr(rsCat.Fields.Item("CAT_NAME").Value)) then Response.Write("SELECTED") : Response.Write("")%> ><%=(rsCat.Fields.Item("CAT_NAME").Value)%></option> <% rsCat.MoveNext() Wend If (rsCat.CursorType > 0) Then rsCat.MoveFirst Else rsCat.Requery End If %> </select> </p> </form> </body> </html> <!--'This part of the If statement is loaded if the browser is netscape! Sorry but this person selects 'the information and has to click the submit button!--> <% Else %> <html> <head><title>dude></title></head> <body> <p>Select from the dropdown menu</p><br> <form ACTION="" METHOD="POST" NAME="form1"> <p><select SIZE="1" NAME="cat_id"> <% While (NOT rsCat.EOF) %> <option value="<%=(rsCat.Fields.Item("CAT_ID").Value)%>" <%if (CStr(rsCat.Fields.Item("CAT_ID").Value) = CStr(rsCat.Fields.Item("CAT_NAME").Value)) then Response.Write("SELECTED") : Response.Write("")%> ><%=(rsCat.Fields.Item("CAT_NAME").Value)%></option> <% rsCat.MoveNext() Wend If (rsCat.CursorType > 0) Then rsCat.MoveFirst Else rsCat.Requery End If End If %> </select> <% rsCAT.close 'conn.close set rsCAT = nothing 'set conn = nothing %> <!-- This shows the resultset that is chosen from the first dropdown box--> <% 'Good coding practices to declare all your local variables 'Does an If statement to see if the request("one") dropdown menu has a value or not If request("one") <> "" Then %> <% set rsSub = Server.CreateObject("ADODB.Recordset") rsSub.ActiveConnection = MM_connDUclassified_STRING rsSub.Source = "SELECT SUB_NAME FROM SUBS WHERE ((SUB_NAME.FIELD)='" & request("cat_id") & "');" rsSub.CursorType = 0 rsSub.CursorLocation = 2 rsSub.LockType = 3 rsSub.Open() rsSub_numRows = 0 %> <html> <head> <title>Load when Empty</title> </head> <body> <form> <p>The results of what was selected from the first dropdown.</p><br> <p><select name="d2" size="1"> <% Do While Not rsSub.EOF %> <option value="<% = rsSub("SUB_NAME") %>"><% = rsSub("SUB_NAME") %></option> <% rsSub.movenext %><% loop %> </select><br> </p> </form> </body> </html> <% rsSubclose 'coM.close set rsSub = nothing 'set coM = nothing %> This part gets loaded when the page first loads, when it first loads it is just a blank dropdown box. <% Else %> <html> <head> <title>Load when Empty</title> </head> <body> <form> <p><select name="d1" size="1"> <option value=""></option> </select><br> </p> </form> </body> </html> <% End If %> |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft Access Help > 2 tables and 2 dropdown lists |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|