Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dependent Drop Down List from DB

    I have an .asp page and want to display two drop down lists, please note the data comes from db values in a table:

    DropDown1: Application
    DropDown2: Server Location

    In the table, I may have multiple instances of the same application name, but the only difference between all instances of say "Office" will be the server name/physical host. How can I remove these duplicate entries in DropDown1, and have it populate DropDown2 with the server location if there are duplicates?

    For example

    DropDown1:
    Office <-- selected (would like to remove duplicates here also)
    Office
    Word
    PPT
    PPT
    PPT

    DropDown2:
    New York
    DC


    Here is my code -> currently with only 1 drop down - not sure how to create a 2nd dependent one.

    Code:
    <SELECT NAME="Sites" style="font-family: Verdana; font-size: 9pt">
    <OPTION> Please select a Application</OPTION><%
    
    If WebSiteName <> "" Then
     	While Not objRS.EOF
     		If objRS("Application_Name") <> "" Then
    			If objRS("Application_Name") = WebSiteName Then
    %>
    <OPTION VALUE="<%=objRS("Application_Name")%>" SELECTED><%=objRS("Application_Name")%></OPTION><%
    				Else
    %>
    <OPTION VALUE="<%=objRS("Application_Name")%>"><%=objRS("Application_Name")%></OPTION><%
    			End If
    		End If
     		objRS.MoveNext
     	WEnd
    Else
     	While Not objRS.EOF
    		If objRS("Application_Name") <> "" Then
    %>
    <OPTION VALUE="<%=objRS("Application_Name")%>"><%=objRS("Application_Name")%></OPTION><%
     		End If
     		objRS.MoveNext
     	WEnd
    End If
    
    objRS.Close
    Set objRS = Nothing
    
    %>
    </SELECT><INPUT TYPE="submit" VALUE="Go" class="buttons" style="font-family: Verdana; font-size: 8pt">
    </FORM>
    <%
    
    If WebSiteName <> "" Then
    	strSQL2 = "SELECT * FROM Application$ WHERE Application_Name = '" & WebSiteName & "'"
    
    	Set objRS2 = objConn.Execute(strSQL2)
    
    	If Err.Number > 0 Then
    		Response.Write "<B>Sorry, the database cannot be accessed.</B>"
    		Response.End
    	End If
     	If objRS2.EOF Then
     		Response.Write "<B>I'm sorry but your query returned no records.</B>"
     		Response.End
     	End If
    %>
    
    <form method="POST" action="thankyou.asp">

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,062
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Use SQL's SELECT DISTINCT keyword to eliminate duplicate entries from the first dropdown. Now, as to filling the 2nd drop down you would be better off assigning the values to a javascript array and then building the 2nd dropdown from the array. this way you prevent a postback to the serverafter the 1st dropdown is selected.

  • #3
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you want to populate the dropdown in pure ASP then here is an example

    http://computer-helpforum.com/asp/as...t+Manufacturer
    See attached for code



    You can add javascript and/or Ajax to make it more user friendly
    http://computer-helpforum.com/asp/aj...t_via_ajax.asp
    Attached Files Attached Files


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •