asp动态级联菜单代码

2018-09-05 18:26

阅读:1422

  JS脚本:
<%
dimrs
dimsql
dimcount
dimrs1
dimsql1
sql=select*fromregionorderbyzoneidasc
setrs=server.createobject(adodb.recordset)
rs.opensql,conn,1,3
%>
<scriptlanguage=JavaScript>
varonecount;
onecount=0;
subcat=newArray();
<%
count=0
dowhilenotrs.eof
%>
subcat[<%=count%>]=newArray(<%=trim(rs(regionname))%>,<%=trim(rs(zoneid))%>,<%=trim(rs(regionid))%>);
<%
count=count+1
rs.movenext
loop
rs.close
setrs=nothing
%>
onecount=<%=count%>;

functionchangelocation(zoneid)
{
document.myform.region.length=0;

varzoneid=zoneid;
vari;
document.myform.region.options[0]=newOption(--地区--,);
for(i=0;i<onecount;i++)
{
if(subcat[i][1]==zoneid)
{
document.myform.region.options[document.myform.region.length]=newOption(subcat[i][0],subcat[i][2]);
}
}

}
</script>

表单内容:
<table>
<form>
<tr>
<td>
<spanclass=STYLE1>*</span>大区:
<selectname=zonesize=1id=zoneonChange=changelocation(document.myform.zone.options[document.myform.zone.selectedIndex].value)>
<optionvalue=0selected>请选择</option>
<%

sql1=select*frombigzoneorderbyzonenameasc
setrs1=server.createobject(adodb.recordset)
rs1.opensql1,conn,1,3
%>
<%whilenotrs1.eof%>
<optionvalue=<%=rs1(zoneid)%>><%=rs1(zonename)%></option>
<%rs1.movenext
wend
rs1.close
setrs1=nothing
%>
</select></td>
<tdwidth=20%><spanclass=STYLE1>*</span>地区:
<selectname=regionsize=1id=region>
<optionvalue=0selected>请选择</option>
</select>
</tr>
</form>
</table>


评论


亲,登录后才可以留言!