Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linked Drop Drop Menus

Status
Not open for further replies.

jcpelejo

Programmer
Jul 29, 2001
70
US
Hello. I am having problems linking my drop down menus so that if you pick one item from the first drop down menu, it filters the next drop down menu. When you select the second item from the second drop down menu it filters the third drop down menu. Once all 3 items are chosen and the person clicks on Submit, the values are saved in a table called [Update Claim Detail Details]. Please advise. I have included the code that I have been working on.

<%@ Language=VBScript %>
<% OPTION EXPLICIT %>

<html>
<head>
<title>Vehicle Description</title>

</head>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>

<%
'------------------------
'Declare all variables
'------------------------
Dim adoCon
Dim strCon
Dim strAccessDB
Dim sqlVehicleYear, sqlVehicleMake, sqlVehicleModel
Dim rsVehicleYear, rsVehicleMake, rsVehicleModel
Dim strYear, strMake, strModel

'--------------------------------
'Create connection to database
'--------------------------------
Set adoCon = Server.CreateObject(&quot;ADODB.Connection&quot;)
strAccessDB = &quot;\fpdb\claim.mdb&quot;
strCon = &quot;DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=patrick; DBQ=&quot; & Server.MapPath(strAccessDB)
adoCon.Open strCon

'-------------------
'Create recordset
'-------------------
Set rsVehicleYear = Server.CreateObject(&quot;ADODB.Recordset&quot;)

'---------------------------------
'Initialize combo box variables
'---------------------------------
strYear = Request(&quot;cboVehicleYear&quot;)
strMake = Request(&quot;cboVehicleMake&quot;)
strModel = Request(&quot;cboVehicleModel&quot;)

'--------------------------
'Initialize SQL statements
'--------------------------
sqlVehicleYear = &quot;SELECT DISTINCT VehicleYear FROM [Vehicle Description]&quot;
sqlVehicleMake = &quot;SELECT DISTINCT VehicleMake FROM [Vehicle Description]&quot;
sqlVehicleModel = &quot;SELECT DISTINCT VehicleModel FROM [Vehicle Description]&quot;


%>
<form name=&quot;frmVehicleDescription&quot; method=&quot;POST&quot; action=&quot;claim.asp&quot;>
<SELECT name=cboVehicleYear LANGUAGE=JavaScript>
<%
'--------------------
'Create a recordset
'--------------------
Set rsVehicleYear = Server.CreateObject(&quot;ADODB.Recordset&quot;)

'----------------------------------
'Open connection to the recordset
'----------------------------------
rsVehicleYear.Open sqlVehicleYear, strCon

'----------------------------------------------------------------
'Verify information is valid and post as a list (1st combo box)
'----------------------------------------------------------------
Do While Not rsVehicleYear.EOF
Response.Write &quot;<OPTION VALUE = '&quot; & rsVehicleYear (&quot;VehicleYear&quot;) & &quot;'>&quot;
Response.Write rsVehicleYear(&quot;VehicleYear&quot;) & &quot;</OPTION>&quot;
rsVehicleYear.MoveNext
Loop

rsVehicleYear.Close
Set rsVehicleYear = Nothing
%>
</SELECT>
<SELECT name=cboVehicleMake LANGUAGE=JavaScript>
<%

'--------------------
'Create a recordset
'--------------------
Set rsVehicleMake = adoCon.Execute(sqlVehicleMake)

'----------------------------------------------------------------
'Verify information is valid and post as a list (2nd combo box)
'----------------------------------------------------------------
Do While Not rsVehicleMake.EOF
Response.Write &quot;<OPTION VALUE = '&quot; & rsVehicleMake (&quot;VehicleMake&quot;) & &quot;'>&quot;
Response.Write rsVehicleMake(&quot;VehicleMake&quot;) & &quot;</OPTION>&quot;
rsVehicleMake.MoveNext
Loop

rsVehicleMake.Close
Set rsVehicleMake = Nothing
%>
</SELECT>


<select name=cboVehicleModel language=JavaScript>
<%
'--------------------
'Create a recordset
'--------------------
Set rsVehicleModel = Server.CreateObject(&quot;ADODB.Recordset&quot;)

'------------------------------------
'Open connection to the recordset
'------------------------------------
rsVehicleModel.Open sqlVehicleModel, strCon

'-----------------------------------------------------------------
'Verify information is valid and post as a list (3rd combo box)
'-----------------------------------------------------------------
Do While Not rsVehicleModel.EOF
Response.Write &quot;<OPTION VALUE = '&quot; & rsVehicleModel (&quot;VehicleModel&quot;) & &quot;'>&quot;
Response.Write rsVehicleModel(&quot;VehicleModel&quot;) & &quot;</OPTION>&quot;
rsVehicleModel.MoveNext
Loop

rsVehicleModel.Close
Set rsVehicleModel = Nothing


%>
</select>
</form>


</body>
</html>
Life is too short to waste...
Julius Pelejo
jcpelejo@hotmail.com
 
Hello. I was able to link the combo boxes but the only thing that I have a problem with is removing all redundant records from the listings. Please advise. I have attached the code that I have.

<%@ Language=VBScript %>
<% Option Explicit %>
<%
Call Main()

Sub Main()
' If the form is submitted, just display the selected country and state
If Request.Form(&quot;cmdSubmit&quot;) <> &quot;&quot; Then
Response.Write &quot;<B> VehicleYear = &quot; & Request.Form(&quot;cboVehicleYear&quot;) & _
&quot; VehicleMake = &quot; & Request.Form(&quot;cboVehicleMake&quot;) & &quot; VehicleModel = &quot; & Request.Form(&quot;cboVehicleModel&quot;) & &quot;</B>&quot;
Exit Sub
End If

Dim objConnection ' ADO Connection object
Dim strAccessDB ' Database name
Dim strCon ' Microsoft Access Driver
Dim strSQL ' SQL query to be executed
Dim strSQL1 ' SQL query to be executed
Dim strSQL2 ' SQL query to be executed
Dim strSQL3 ' SQL query to be executed

Set objConnection = Server.CreateObject(&quot;ADODB.Connection&quot;)
strAccessDB = &quot;\fpdb\claim.mdb&quot;
strCon = &quot;DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=patrick; DBQ=&quot; & Server.MapPath(strAccessDB)
objConnection.Open strCon

Dim rsVehicleYear ' recordset that holds the Vehicle Year Information
Dim rsVehicleMake ' recordset that holds the Country Information
Dim rsVehicleModel ' recordset that holds the State Information

Dim strVehicleYear ' holds the Vehicle Year
Dim strVehicleMake ' holds the Country ID
Dim strVehicleModel ' holds the State ID

Set rsVehicleYear = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Set rsVehicleMake = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Set rsVehicleModel = Server.CreateObject(&quot;ADODB.Recordset&quot;)

strSQL = &quot;SELECT DISTINCT * FROM [Vehicle Description]&quot;


Set rsVehicleYear = objConnection.Execute(strSQL)

' Check if there is a Vehicle Year selected by the user
' If not, just take the first Vehicle Year as the
' filter for the Vehicle Make List
strVehicleYear = Request.Form(&quot;cboVehicleYear&quot;)
If strVehicleYear = &quot;&quot; Then
If Not rsVehicleYear.EOF Then
strVehicleYear = rsVehicleYear(&quot;VehicleYear&quot;)
End If
End If

If strVehicleYear <> &quot;&quot; Then
strSQL = &quot;SELECT DISTINCT * FROM [Vehicle Description] WHERE VehicleYear = '&quot; & strVehicleYear & &quot;'&quot;
Set rsVehicleMake = objConnection.Execute(strSQL)
strVehicleMake = Request.Form(&quot;cboVehicleMake&quot;)
If strVehicleMake = &quot;&quot; Or Request.Form(&quot;hid_VehicleYear_Changed&quot;) = &quot;True&quot; Then
If Not rsVehicleMake.EOF Then
strVehicleMake = rsVehicleMake(&quot;VehicleMake&quot;)
End If
End If
strSQL = &quot;SELECT DISTINCT * FROM [Vehicle Description] WHERE VehicleMake='&quot; & strVehicleMake & &quot;'&quot; & _
&quot; AND VehicleYear = '&quot; & strVehicleYear & &quot;'&quot;
Set rsVehicleModel = objConnection.Execute(strSQL)
End If
%>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
</HEAD>
<BODY>
<CENTER>
<FORM NAME=frmHierarchy METHOD=post ACTION=&quot;Hierarchy.asp&quot;>
<INPUT TYPE=HIDDEN NAME=hid_VehicleYear_Changed>
<INPUT TYPE=HIDDEN NAME=hid_VehicleMake_Changed>
<P><H2>Hierarchial Selection of Items</H2></P>
<TABLE CELLSPACING=5 CELLPADDING=5 BORDER=0 ALIGN=&quot;CENTER&quot;>
<TR>
<TD>Vehicle Year: </TD>
<TD><SELECT id=cboVehicleYear name=cboVehicleYear onchange=&quot;ChangeVehicleYear()&quot;>
<%
' Add the Vehicle Year to the list
If Not rsVehicleYear.EOF Then
Do While Not rsVehicleYear.EOF
strVehicleYear = rsVehicleYear(&quot;VehicleYear&quot;)
If rsVehicleYear(&quot;VehicleYear&quot;) = Request.Form(&quot;cboVehicleYear&quot;) Then %>
<OPTION VALUE=&quot;<%=rsVehicleYear(&quot;VehicleYear&quot;)%>&quot; SELECTED> <%=strVehicleYear%></OPTION>
<%
Else
%>
<OPTION VALUE=&quot;<%=rsVehicleYear(&quot;VehicleYear&quot;)%>&quot; > <%=strVehicleYear%></OPTION>
<%
End If
rsVehicleYear.MoveNext
Loop
End If
'Reset the record pointer to the first record
rsVehicleYear.MoveFirst
%>
</SELECT></TD>
</TR>
<TR>
<TD>Vehicle Make: </TD>
<TD><SELECT id=cboVehicleMake name=cboVehicleMake onchange=&quot;ChangeVehicleMake()&quot; >
<%
' Add the Vehicle Make to the list
If Not rsVehicleMake.EOF Then
Do While Not rsVehicleMake.EOF
strVehicleMake = rsVehicleMake(&quot;VehicleMake&quot;)
If rsVehicleMake(&quot;VehicleMake&quot;) = Request.Form(&quot;cboVehicleMake&quot;) Then
%>
<OPTION Value=&quot;<%=rsVehicleMake(&quot;VehicleMake&quot;)%>&quot; SELECTED> <%=strVehicleMake%></OPTION>
<%
Else
%>
<OPTION Value=&quot;<%=rsVehicleMake(&quot;VehicleMake&quot;)%>&quot; > <%=strVehicleMake%></OPTION>
<%
End If
rsVehicleMake.MoveNext
Loop
End If

'Reset the record pointer to the first record
rsVehicleMake.MoveFirst
%>
</SELECT></TD>
</TR>
<TR>
<TD>Vehicle Model: </TD>
<TD><SELECT id=cboVehicleModel name=cboVehicleModel>
<%
' Add the Vehicle Model to the list
If Not rsVehicleModel.EOF Then
Do While Not rsVehicleModel.EOF
strVehicleModel = rsVehicleModel(&quot;VehicleModel&quot;) %>
<OPTION Value=&quot;<%=rsVehicleModel(&quot;VehicleModel&quot;)%>&quot; > <%=strVehicleModel%></OPTION>
<%
rsVehicleModel.MoveNext
Loop
End If
%>
</SELECT></TD>
</TR>
</TABLE>
<P><INPUT id=cmdSubmit name=cmdSubmit type=submit value=Submit></P>
<P>&nbsp;</P></FORM>
</FORM>
</CENTER>
</BODY>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function ChangeVehicleYear()
{
document.frmHierarchy.hid_VehicleYear_Changed.value = &quot;True&quot;;
document.frmHierarchy.submit();
}

function ChangeVehicleMake()
{
document.frmHierarchy.hid_VehicleMake_Changed.value = &quot;True&quot;;
document.frmHierarchy.submit();
}
</SCRIPT>
</HTML>
<%
' Release the connection and recordsets
Set objConnection = Nothing
Set rsVehicleYear = Nothing
Set rsVehicleMake = Nothing
Set rsVehicleModel = Nothing
End Sub
%>
Life is too short to waste...
Julius Pelejo
jcpelejo@hotmail.com
 
Hello. I was able to link the combo boxes but the only thing that I have a problem with is removing all redundant records from the listings. Please advise. I have attached the code that I have.

<%@ Language=VBScript %>
<% Option Explicit %>
<%
Call Main()

Sub Main()
' If the form is submitted, just display the selected Vehicle Make and Vehicle Model
If Request.Form(&quot;cmdSubmit&quot;) <> &quot;&quot; Then
Response.Write &quot;<B> VehicleYear = &quot; & Request.Form(&quot;cboVehicleYear&quot;) & _
&quot; VehicleMake = &quot; & Request.Form(&quot;cboVehicleMake&quot;) & &quot; VehicleModel = &quot; & Request.Form(&quot;cboVehicleModel&quot;) & &quot;</B>&quot;
Exit Sub
End If

Dim objConnection ' ADO Connection object
Dim strAccessDB ' Database name
Dim strCon ' Microsoft Access Driver
Dim strSQL ' SQL query to be executed
Dim strSQL1 ' SQL query to be executed
Dim strSQL2 ' SQL query to be executed
Dim strSQL3 ' SQL query to be executed

Set objConnection = Server.CreateObject(&quot;ADODB.Connection&quot;)
strAccessDB = &quot;\fpdb\claim.mdb&quot;
strCon = &quot;DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=patrick; DBQ=&quot; & Server.MapPath(strAccessDB)
objConnection.Open strCon

Dim rsVehicleYear ' recordset that holds the Vehicle Year Information
Dim rsVehicleMake ' recordset that holds the Country Information
Dim rsVehicleModel ' recordset that holds the State Information

Dim strVehicleYear ' holds the Vehicle Year
Dim strVehicleMake ' holds the Country ID
Dim strVehicleModel ' holds the State ID

Set rsVehicleYear = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Set rsVehicleMake = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Set rsVehicleModel = Server.CreateObject(&quot;ADODB.Recordset&quot;)

strSQL = &quot;SELECT DISTINCT * FROM [Vehicle Description]&quot;


Set rsVehicleYear = objConnection.Execute(strSQL)

' Check if there is a Vehicle Year selected by the user
' If not, just take the first Vehicle Year as the
' filter for the Vehicle Make List
strVehicleYear = Request.Form(&quot;cboVehicleYear&quot;)
If strVehicleYear = &quot;&quot; Then
If Not rsVehicleYear.EOF Then
strVehicleYear = rsVehicleYear(&quot;VehicleYear&quot;)
End If
End If

If strVehicleYear <> &quot;&quot; Then
strSQL = &quot;SELECT DISTINCT * FROM [Vehicle Description] WHERE VehicleYear = '&quot; & strVehicleYear & &quot;'&quot;
Set rsVehicleMake = objConnection.Execute(strSQL)
strVehicleMake = Request.Form(&quot;cboVehicleMake&quot;)
If strVehicleMake = &quot;&quot; Or Request.Form(&quot;hid_VehicleYear_Changed&quot;) = &quot;True&quot; Then
If Not rsVehicleMake.EOF Then
strVehicleMake = rsVehicleMake(&quot;VehicleMake&quot;)
End If
End If
strSQL = &quot;SELECT DISTINCT * FROM [Vehicle Description] WHERE VehicleMake='&quot; & strVehicleMake & &quot;'&quot; & _
&quot; AND VehicleYear = '&quot; & strVehicleYear & &quot;'&quot;
Set rsVehicleModel = objConnection.Execute(strSQL)
End If
%>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
</HEAD>
<BODY>
<CENTER>
<FORM NAME=frmHierarchy METHOD=post ACTION=&quot;Hierarchy.asp&quot;>
<INPUT TYPE=HIDDEN NAME=hid_VehicleYear_Changed>
<INPUT TYPE=HIDDEN NAME=hid_VehicleMake_Changed>
<P><H2>Hierarchial Selection of Items</H2></P>
<TABLE CELLSPACING=5 CELLPADDING=5 BORDER=0 ALIGN=&quot;CENTER&quot;>
<TR>
<TD>Vehicle Year: </TD>
<TD><SELECT id=cboVehicleYear name=cboVehicleYear onchange=&quot;ChangeVehicleYear()&quot;>
<%
' Add the Vehicle Year to the list
If Not rsVehicleYear.EOF Then
Do While Not rsVehicleYear.EOF
strVehicleYear = rsVehicleYear(&quot;VehicleYear&quot;)
If rsVehicleYear(&quot;VehicleYear&quot;) = Request.Form(&quot;cboVehicleYear&quot;) Then %>
<OPTION VALUE=&quot;<%=rsVehicleYear(&quot;VehicleYear&quot;)%>&quot; SELECTED> <%=strVehicleYear%></OPTION>
<%
Else
%>
<OPTION VALUE=&quot;<%=rsVehicleYear(&quot;VehicleYear&quot;)%>&quot; > <%=strVehicleYear%></OPTION>
<%
End If
rsVehicleYear.MoveNext
Loop
End If
'Reset the record pointer to the first record
rsVehicleYear.MoveFirst
%>
</SELECT></TD>
</TR>
<TR>
<TD>Vehicle Make: </TD>
<TD><SELECT id=cboVehicleMake name=cboVehicleMake onchange=&quot;ChangeVehicleMake()&quot; >
<%
' Add the Vehicle Make to the list
If Not rsVehicleMake.EOF Then
Do While Not rsVehicleMake.EOF
strVehicleMake = rsVehicleMake(&quot;VehicleMake&quot;)
If rsVehicleMake(&quot;VehicleMake&quot;) = Request.Form(&quot;cboVehicleMake&quot;) Then
%>
<OPTION Value=&quot;<%=rsVehicleMake(&quot;VehicleMake&quot;)%>&quot; SELECTED> <%=strVehicleMake%></OPTION>
<%
Else
%>
<OPTION Value=&quot;<%=rsVehicleMake(&quot;VehicleMake&quot;)%>&quot; > <%=strVehicleMake%></OPTION>
<%
End If
rsVehicleMake.MoveNext
Loop
End If

'Reset the record pointer to the first record
rsVehicleMake.MoveFirst
%>
</SELECT></TD>
</TR>
<TR>
<TD>Vehicle Model: </TD>
<TD><SELECT id=cboVehicleModel name=cboVehicleModel>
<%
' Add the Vehicle Model to the list
If Not rsVehicleModel.EOF Then
Do While Not rsVehicleModel.EOF
strVehicleModel = rsVehicleModel(&quot;VehicleModel&quot;) %>
<OPTION Value=&quot;<%=rsVehicleModel(&quot;VehicleModel&quot;)%>&quot; > <%=strVehicleModel%></OPTION>
<%
rsVehicleModel.MoveNext
Loop
End If
%>
</SELECT></TD>
</TR>
</TABLE>
<P><INPUT id=cmdSubmit name=cmdSubmit type=submit value=Submit></P>
<P> </P></FORM>
</FORM>
</CENTER>
</BODY>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function ChangeVehicleYear()
{
document.frmHierarchy.hid_VehicleYear_Changed.value = &quot;True&quot;;
document.frmHierarchy.submit();
}

function ChangeVehicleMake()
{
document.frmHierarchy.hid_VehicleMake_Changed.value = &quot;True&quot;;
document.frmHierarchy.submit();
}
</SCRIPT>
</HTML>
<%
' Release the connection and recordsets
Set objConnection = Nothing
Set rsVehicleYear = Nothing
Set rsVehicleMake = Nothing
Set rsVehicleModel = Nothing
End Sub
%>
Life is too short to waste...
Julius Pelejo
jcpelejo@hotmail.com
 
I have removed all redundant records by modifying two SQL statements. The two statements that I modified are the following:

Old SQL Statement
SELECT DISTINCT * FROM [Vehicle Description] WHERE VehicleYear = '&quot; & strVehicleYear & &quot;'&quot;
New SQL Statement
SELECT DISTINCT VehicleYear, VehicleMake FROM [Vehicle Description] WHERE VehicleYear = '&quot; & strVehicleYear & &quot;'&quot;

Old Recordset Statement
strSQL = &quot;SELECT DISTINCT * FROM [Vehicle Description]&quot;
Set rsVehicleYear = objConnection.Execute(strSQL)
New Recordset Statement
strSQL1 = &quot;SELECT DISTINCT VehicleYear FROM [Vehicle Description]&quot;
Set rsVehicleYear = objConnection.Execute(strSQL1) Life is too short to waste...
Julius Pelejo
jcpelejo@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top