<form name=myform method=post action=''>
<tr bgcolor="#F6FAFD"><%
set rs = server.CreateObject("adodb.recordset")
rs.open "select categoryid,category from category where first=1 order by categoryorder",conn,1,1
if rs.eof and rs.bof then
response.Write "<tr><td align=center>還沒有商品分類</td></tr>"
else
%>
<td height="30" colspan="2" align="center"><span class="style16">
<select name="categoryid" onChange="changelocation(document.myform.categoryid.options[document.myform.categoryid.selectedIndex].value)">
<option value="----品牌----" selected>----品牌----</option>
<% do while not rs.eof %>
<option value="<%=trim(rs("categoryid"))%>"><%=trim(rs("category"))%></option>
<%
rs.movenext
loop
end if
rs.close
set rs = nothing
'conn.Close
'set conn = nothing
%>
</select>
</span></td>
</tr>
<tr bgcolor="#F6FAFD">
<td height="30" colspan="2" align="center"><span class="style16">
<select name="sortsid">
<option selected value>---請選分類---</option>
</select>
</span></td>
</tr></form>
<SCRIPT language="javascript">
var onecount;
onecount=0;
subcat = new Array();
<%
count = 0
do while not rs1.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rs1("sorts"))%>","<%= trim(rs1("categoryid"))%>","<%= trim(rs1("sortsid"))%>");
<%
count = count + 1
rs1.movenext
loop
rs1.close
%>
onecount=<%=count%>;
function changelocation(locationid)
...{
document.myform.sortsid.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
...{
if (subcat[i][1] == locationid)
...{
document.myform.sortsid.options[document.myform.sortsid.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</SCRIPT>
注意:1、數組存放順序(哪個是與一級菜單的值) 2、數組中的值要用雙引號""引起來 3、javascript:new Option(text, value)