K
Kingdom
I'm using this script to dynamicaly populate 2 dropdowns and dispaly the
results. Choose a component type from the first drop down, lets say
'car' and the second box will list all the car 'manufacturers' and the
display will then provide all the rest of the info from the other fields.
I need to eliminate all the duplicates in the First Drop Down as it
currently displays an entry for every record, many are identical, I might
have over 2,000 records but only around 15 componet_types, which would
ideal for this drop down.
CODE ASP 3
========================================
<!-- Start First Drop Down -->
<%
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.Open Application("Database1_connectionstring")
Set objRS = objDC.Execute("Select Component_Type FROM Parts_Table")
%>
<table border="0" cellpadding="0" cellspacing="0" style="border-
collapse: collapse" width="100%" id="AutoNumber1">
<tr>
<td width="3%"> </td>
<td width="77%">
<FORM METHOD="POST" NAME="Form1" ACTION="systems.asp">
<p align="left">
<SELECT NAME="Component_Type" SIZE="1" ONCHANGE=Form1.submit()>
<option selected><% = Request.Form("Component_Type") %>
</option>
<%
' Continue until we get to the end of the recordset.
Do Until objRS.EOF
' For each record we create a option tag and set it's value to
the Component_Type
%>
<OPTION><%= objRS("Component_Type") %></OPTION>
<%
' Get next record
objRS.MoveNext
Loop
%>
</SELECT> <b><font face="Arial" size="2" color="#000080">Choose a
Component Type</font></b></p>
</FORM>
<%
' Close Data Access Objects and free DB variables
objRS.Close
Set objRS = Nothing
objDC.Close
Set objDC = Nothing
%>
<!-- End first Drop Down -->
<!--Second drop down -->
<%
'Some code to hide the second drop down until we make a selection from
the first
IF Request.Form("Component_Type") = "" Then
Else
'If Component_Type has a value then we get a list of parts for the second
drop down
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.Open Application("Database1_connectionstring")
Set objRS = objDC.Execute("Select Products FROM Parts_Table WHERE
Component_Type = '" & Request.Form("Component_Type") & "'")
%>
<FORM METHOD="POST" NAME="Form2" ACTION="systems.asp">
<p align="left">
<font face="Arial"><font color="#008080"><b>
<SELECT NAME="Products" SIZE="1" ONCHANGE=Form2.submit()>
<option selected><% = Request.Form("Products") %></option>
<%
' Continue until we get to the end of the recordset.
Do Until objRS.EOF
' For each record we create a option tag and set it's value to
the Products
%>
<OPTION><%= objRS("Products") %></OPTION>
<%
' Get next record
objRS.MoveNext
Loop
%>
<%
'Set a hidden value in the second form for the Component_Type
'so we can pass it along with the Products to the next query
%>
</SELECT></b></font><b><font size="2" color="#008080"> </font>
<font size="2" color="#000080">Choose a Product</font></b><font
color="#000080"><b><input type="hidden" name="Component_Type" value="<% =
Request.Form("Component_Type") %>"></b></font></font></p>
</FORM>
<%
' Close Data Access Objects and free DB variables
objRS.Close
Set objRS = Nothing
objDC.Close
Set objDC = Nothing
End IF
%>
<!-- Display the records -->
</td>
<td width="20%"><img border="0" src="compsystem200X120.gif"></td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" style="border-
collapse: collapse" width="600" id="AutoNumber2">
<tr>
<td width="55" valign="top"><b>
<font face="Arial" size="2" color="#000000">Details: </font><font
face="Arial" size="2" color="#000080"> <% Response.Write Products & " " &
Component_Type %> </font>
</b>
</td>
<td width="311">
<%
'Make sure we have submitted a Product and don't show results until we do
IF Request.Form("Products") = "" Then
Else
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.Open Application("Database1_connectionstring")
Set objRS = objDC.Execute("Select * FROM Parts_Table WHERE Component_Type
= '" & Request.Form("Component_Type") & "' AND Products = '" &
Request.Form("Products") & "'")
'Loop through the database and assign the appropriate values to variables
'that we will use later
Do Until objRS.EOF
Manufacturer = objRS("Manufacturer")
Description = objRS("Description")
Model_No = objRS("Model_No")
Products = objRS("Products")
Part_Number = objRS("Part_Number")
Price = objRS("Price")
Image = objRS("Image")
Options = objRS("Options")
Component_Type = objRS("Component_Type")
objRS.MoveNext
Loop
objRS.Close
Set objRS = Nothing
objDC.Close
Set objDC = Nothing
%>
</div>
<p align="left"><b><font face="Arial" size="2" color="#000080"><%
Response.Write Products & " - " & Component_Type %> </font>
</b>
<br>
<font face="Arial" size="2" color="#000080">
<%
'Set up the display of the record
Response.Write "Manufacturer - " & Manufacturer & "<br>"
Response.Write Description & "<br>"
Response.Write "Model No. " & Model_No & "<br>"
Response.Write Products & " - " & "Part No. " & Part_Number & " Price
" & Price & "<br>"
IF Options <> "" Then
Response.Write "Options:- " & Options & "<br>"
Response.Write "Image " & Image & "<br>"
End IF
End IF
%>
results. Choose a component type from the first drop down, lets say
'car' and the second box will list all the car 'manufacturers' and the
display will then provide all the rest of the info from the other fields.
I need to eliminate all the duplicates in the First Drop Down as it
currently displays an entry for every record, many are identical, I might
have over 2,000 records but only around 15 componet_types, which would
ideal for this drop down.
CODE ASP 3
========================================
<!-- Start First Drop Down -->
<%
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.Open Application("Database1_connectionstring")
Set objRS = objDC.Execute("Select Component_Type FROM Parts_Table")
%>
<table border="0" cellpadding="0" cellspacing="0" style="border-
collapse: collapse" width="100%" id="AutoNumber1">
<tr>
<td width="3%"> </td>
<td width="77%">
<FORM METHOD="POST" NAME="Form1" ACTION="systems.asp">
<p align="left">
<SELECT NAME="Component_Type" SIZE="1" ONCHANGE=Form1.submit()>
<option selected><% = Request.Form("Component_Type") %>
</option>
<%
' Continue until we get to the end of the recordset.
Do Until objRS.EOF
' For each record we create a option tag and set it's value to
the Component_Type
%>
<OPTION><%= objRS("Component_Type") %></OPTION>
<%
' Get next record
objRS.MoveNext
Loop
%>
</SELECT> <b><font face="Arial" size="2" color="#000080">Choose a
Component Type</font></b></p>
</FORM>
<%
' Close Data Access Objects and free DB variables
objRS.Close
Set objRS = Nothing
objDC.Close
Set objDC = Nothing
%>
<!-- End first Drop Down -->
<!--Second drop down -->
<%
'Some code to hide the second drop down until we make a selection from
the first
IF Request.Form("Component_Type") = "" Then
Else
'If Component_Type has a value then we get a list of parts for the second
drop down
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.Open Application("Database1_connectionstring")
Set objRS = objDC.Execute("Select Products FROM Parts_Table WHERE
Component_Type = '" & Request.Form("Component_Type") & "'")
%>
<FORM METHOD="POST" NAME="Form2" ACTION="systems.asp">
<p align="left">
<font face="Arial"><font color="#008080"><b>
<SELECT NAME="Products" SIZE="1" ONCHANGE=Form2.submit()>
<option selected><% = Request.Form("Products") %></option>
<%
' Continue until we get to the end of the recordset.
Do Until objRS.EOF
' For each record we create a option tag and set it's value to
the Products
%>
<OPTION><%= objRS("Products") %></OPTION>
<%
' Get next record
objRS.MoveNext
Loop
%>
<%
'Set a hidden value in the second form for the Component_Type
'so we can pass it along with the Products to the next query
%>
</SELECT></b></font><b><font size="2" color="#008080"> </font>
<font size="2" color="#000080">Choose a Product</font></b><font
color="#000080"><b><input type="hidden" name="Component_Type" value="<% =
Request.Form("Component_Type") %>"></b></font></font></p>
</FORM>
<%
' Close Data Access Objects and free DB variables
objRS.Close
Set objRS = Nothing
objDC.Close
Set objDC = Nothing
End IF
%>
<!-- Display the records -->
</td>
<td width="20%"><img border="0" src="compsystem200X120.gif"></td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" style="border-
collapse: collapse" width="600" id="AutoNumber2">
<tr>
<td width="55" valign="top"><b>
<font face="Arial" size="2" color="#000000">Details: </font><font
face="Arial" size="2" color="#000080"> <% Response.Write Products & " " &
Component_Type %> </font>
</b>
</td>
<td width="311">
<%
'Make sure we have submitted a Product and don't show results until we do
IF Request.Form("Products") = "" Then
Else
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.Open Application("Database1_connectionstring")
Set objRS = objDC.Execute("Select * FROM Parts_Table WHERE Component_Type
= '" & Request.Form("Component_Type") & "' AND Products = '" &
Request.Form("Products") & "'")
'Loop through the database and assign the appropriate values to variables
'that we will use later
Do Until objRS.EOF
Manufacturer = objRS("Manufacturer")
Description = objRS("Description")
Model_No = objRS("Model_No")
Products = objRS("Products")
Part_Number = objRS("Part_Number")
Price = objRS("Price")
Image = objRS("Image")
Options = objRS("Options")
Component_Type = objRS("Component_Type")
objRS.MoveNext
Loop
objRS.Close
Set objRS = Nothing
objDC.Close
Set objDC = Nothing
%>
</div>
<p align="left"><b><font face="Arial" size="2" color="#000080"><%
Response.Write Products & " - " & Component_Type %> </font>
</b>
<br>
<font face="Arial" size="2" color="#000080">
<%
'Set up the display of the record
Response.Write "Manufacturer - " & Manufacturer & "<br>"
Response.Write Description & "<br>"
Response.Write "Model No. " & Model_No & "<br>"
Response.Write Products & " - " & "Part No. " & Part_Number & " Price
" & Price & "<br>"
IF Options <> "" Then
Response.Write "Options:- " & Options & "<br>"
Response.Write "Image " & Image & "<br>"
End IF
End IF
%>