reportingbuzz
MIS
Hi,
I have built a small ASP sample page which pulls data from the Northwind tables - Categories, Products.
I have already populated the 2 dropdown boxes. I have an onchange event attached to the first select box - Category so that with change to the dropdwon, the 2nd dropdown would show the respective products for that category. How can I link the two. How can I take the selected value of the Category and pass it to the Products dropdown.
Thanks.
My code is:
I have built a small ASP sample page which pulls data from the Northwind tables - Categories, Products.
I have already populated the 2 dropdown boxes. I have an onchange event attached to the first select box - Category so that with change to the dropdwon, the 2nd dropdown would show the respective products for that category. How can I link the two. How can I take the selected value of the Category and pass it to the Products dropdown.
Thanks.
My code is:
Code:
<!--#INCLUDE Virtual="/Scripts/Padmaja/Testing2/DB_Northwind.asp"-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<title>Dependable Drop Down</title>
<script type="text/javascript">
function submitValue(str)
{
f = document.Customers
str = f.category.value;
f.hCategory.value = str;
}
</script>
</head>
<body>
<form name="Customers" id="Customers" method="POST" action="">
<input type="text" name="hCategory">
<%
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")
sSQL = "SELECT CategoryID, CategoryName FROM Categories"
rs.open sSQL, Conn
Dim aCategory
If not rs.EOF Then
'Dump the recordset into the above array
aCategory = rs.getRows()
rs.Close
Set rs = Nothing
End If
Dim iRows
%>
Category:
<select name="category" id="category" onChange="submitValue(this);">
<option value="">Select Categories</option>
<%
For iRows = 0 to UBound(aCategory,2)
%>
<option value="<%=aCategory(0,iRows)%>"><%=aCategory(1,iRows)%></option>
<%
Next
%>
</select>
<%
Dim rs1
Set rs1 = Server.CreateObject("ADODB.Recordset")
sSQL1 = "SELECT CategoryID, ProductName, ProductID FROM Products " & _
"where CategoryID = " & Request.form("hCategory") & " " & _
"order by ProductName "
'response.Write sSql1
'response.end
rs1.open sSQL1, Conn
Dim aProducts
If not rs1.EOF Then
'Dump the recordset into the above array
aProducts = rs1.getRows()
rs1.Close
Set rs1 = Nothing
End If
%>
Products:
<select name="product" id="product">
<option value="">Select Product</option>
<%
For i = 0 to UBound(aProducts,2)
%>
<option value=""><%=aProducts(1,i)%></option>
<%
Next
%>
</select>
</form>
</body>
</html>