Jump to content

Linking combo boxes


bairdb

Recommended Posts

I was wondering if anyone knows how to link combo boxes, that are populated from an access database, so if you click on a choice in one combo box it will display the associated data in the second combo box.

Link to comment
Share on other sites

I was wondering if anyone knows how to link combo boxes, that are populated from an access database, so if you click on a choice in one combo box it will display the associated data in the second combo box.

Hi bairdb,You should use an onChange event in your first combo box, then catch the variable you selected to build the second combo box. Here is my version, you just need to add your connection.inc and your 2 queries. Hope it will be helpfull,JeromecmbBox.asp
<%@ Language=VBScript%><!-- #INCLUDE FILE = "../connection.inc" --><%Dim cmbItem1, cmbItem2 cmbItem1 = Trim(Request("cmbItem1"))%><html><head><title>Combo box</title></head><body><form name="frm" method="post" action="cmbBox.asp"><!--Here, you should insert your loop and your sql query to populate the first combo box...--><select name="cmbItem1" onChange="submit();"><option value="">- - - -</option><option value="Item1" <%If cmbItem1="Item1" Then Response.Write("SELECTED") End If%>>Item1</option><option value="Item2" <%If cmbItem1="Item2" Then Response.Write("SELECTED") End If%>>Item2</option><option value="Item3" <%If cmbItem1="Item3" Then Response.Write("SELECTED") End If%>>Item3</option></select><%'Use the variable cmbItem to make your second sql query and populate the second combo box...If Len(cmbItem1) Then Response.Write("<select name=""cmbItem2""><option value=""" & cmbItem1 & """>" & cmbItem1 & "</option></select>")End If%></form></body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...