有俩个表 class1 有 大类id , 大类名称
class2 有 小类id , 小类名称,大类id
<!--#include file="conn.asp"-->
<% set rs=server.createobject("adodb.recordset")
set rs1=server.createobject("adodb.recordset")
%>大类
<select name="TypeID" id="TypeID" onChange="JavaScript:ShowSubType(this.options[this.selectedIndex].tag)">
<option value="">选择大类</option>
<%
Dim RecordCount,BTypeArr
Rs.Open "Select 大类名称,大类ID from class1",Conn,1,1
RecordCount=Rs.RecordCount
If RecordCount>0 Then
Redim BTypeArr(RecordCount-1)
For i=0 To RecordCount-1
SqlStr="Select 小类ID,小类名称 From class2 Where 大类ID=" & Rs("大类ID")
Rs1.Open SqlStr,Conn,1,1
While Not Rs1.Eof
BTypeArr(i)=BTypeArr(i) & "<option value='" & Rs1("小类ID") & "'>" & Rs1("小类名称") & "</option>"
Rs1.MoveNext
Wend
Rs1.Close
%>
<option value="<%=Rs("大类ID")%>" tag=<%=i%>><%=Rs("大类名称")%></option>
<%
Rs.MoveNext
Next
End If
Rs.Close
%>
</select>
小类
<select name="SubTypeID">
<option value="">选择小类</option>
</select>
<%If RecordCount>0 Then%>
<script language="JavaScript">
var BTypeArr=new Array();
<%
For i=0 To RecordCount-1
%>
BTypeArr[<%=i%>]="<%=BTypeArr(i)%>";
<%
Next
%>
function ShowSubType(Index)
{
document.all.SubTypeID.outerHTML="<select name='SubTypeID'><option value=''>选择小类</option>" + BTypeArr[Index] + "</select>";
}
</script>
<%End If%>