I’m trying to create a category and subcategory dropdown list in a form that is database driven. I’ve done several websearches and haven’t turned up much. I did turn up this link but can’t get it to work and the e-mail address on the site bounces back undeliverable.
[url]http://www.4guysfromrolla.com/aspscripts/printpage.asp?REF=/webtech/101099-1.shtml
I have a SQL database with one table called Category with 3 fields, ID=autonumber, Dept and Subitem. I prefilled this fields with data. I can get the first drop down list working without the code on the link but it’s trying to get the sublist to populate based on the first. I hope this makes sense.
I even tried to make another table in my database to replicate what was in the link I found but that didn’t seem to help either. Table 2 is called Subcategory with 3 fields, TaskID=autonumber, Task, and Taskof.
Here’s my code and mind you I’m not really a programmer. I can tweak it but can’t really write it. If some of the code looks strange, I use Dreamweaver so it wrote that code.
<%
Dim RS3
Dim RS3_numRows
Set RS3 = Server.CreateObject(“ADODB.Recordset”)
RS3.ActiveConnection = MM_AdminTime_STRING
RS3.Source = “SELECT * FROM dbo.Category”
RS3.CursorType = 0
RS3.CursorLocation = 2
RS3.LockType = 1
RS3.Open()
RS3_numRows = 0
%>
<html>
<!– DW6 –>
<head>
<script language = “JavaScript”>
function subcat()
cat = document.subad.Dept[document.subad.Dept.selectedIndex].value;
url = “updatetest.asp?cat=”
url = url + cat;
window.location.href< = url;
function sublist(inform, selecteditem)
inform.Subitem.length = 0
<%
count= 0
y=0
do while not RS3.EOF
%>
x = <%= trim(y) %>
subcat = new Array();
subcatagorys = “<%= trim(rs3(“Subitem”))%>”
subcatagoryof = “<%= trim(rs3(“Dept”))%>”
subcat[x,0] = subcatagorys;
subcat[x,1] = subcatagoryof;
if (subcat[x,1] == selecteditem)
{
var option<%= trim(count) %> = new Option(subcat[x,0], subcat[x,1])
inform.Subitem.options[inform.Subitem.length]=option <%= trim(count)%>
<%
count = count + 1
y = y + 1
rs3.movenext
loop
%>
</script>
Any help is appreciated. Thanks.
Judi