Pcook CMS V2.3 Beta 上线测试!
您现在的位置:首页 >> 编程技巧 >> 信息正文

asp+js二级联动下拉菜单实现方式

2008-11-15 18:02:14 来源: 网络 作者:站长 访问:175 次 被顶:7 次 字号:【

<!--#include file="conn.asp"-->
<body onLoad="init()">
<form name="formxl" action="?type=add" method="post">
<%
dim rs1,rs2,rs3,count1,count2,count3

set rs1=server.CreateObject("Adodb.recordSet")
sql="select * from ca_cd"
rs1.open sql,conn,1,1
%>
<script language="javascript">
var Pcount=0;
var subCat1 = new Array();
<%
count1=0
do while not rs1.eof
%>
subCat1[<%=count1%>]=new Array("<%=rs1("cd_id")%>","<%=rs1("cd_name")%>");
<%
rs1.movenext
count1=count1+1
loop
rs1.close
set rs1=nothing
%>
Pcount=<%=count1%>
function init(){
var i;
var j;
document.formxl.xl_chandi.length=0;
document.formxl.xl_chandi.options[0]=new Option("==所选择的产地==","");
for(i=0;i<Pcount;i++){
document.formxl.xl_chandi.options[document.formxl.xl_chandi.length]=
new Option(subCat1[i][1],subCat1[i][0]);
}}
</script>

<%
set rs2=server.CreateObject("Adodb.recordSet")
sql="select * from ca_pp"
rs2.open sql,conn,1,1
%>
<script language="javascript">
var Ccount=0;
var subCat2=new Array();
<%
count2=0
do while not rs2.eof
%>
subCat2[<%=count2%>]=new Array("<%=rs2("pp_name")%>","<%=rs2("pp_name")%>","<%=rs2("pp_chandi")%>");
<%
count2=count2+1
rs2.movenext
loop
rs2.close
set rs2=nothing
%>
Ccount=<%=count2%>
function changedCity(cityId){
var i;
document.formxl.xl_pinpai.length=0;
document.formxl.xl_pinpai.options[0]=new Option("==所选择的品牌==","");
for(i=0;i<Ccount;i++){
if(subCat2[i][2]==cityId){
document.formxl.xl_pinpai.options[document.formxl.xl_pinpai.length]=
new Option(subCat2[i][1],subCat2[i][0]);
}}}
</script>

<select name="xl_chandi" id="xl_chandi" onChange="changedCity(document.formxl.xl_chandi.options[document.formxl.xl_chandi.selectedIndex].value)" style="WIDTH: 130px" >
<option value="">==请选择的产地==</option>
</select>
<select name="xl_pinpai" id="xl_pinpai" onChange="changedBorough(document.formxl.xl_pinpai.options[document.formxl.xl_pinpai.selectedIndex].value)" style="WIDTH: 130px">
<option value="">==请选择的品牌==</option>
</select>
<input name="xl_name" value="" size="30">&nbsp;&nbsp;&nbsp;&nbsp;
<input name="submit" type="submit" value="添加">
</form>

打印本文   加入收藏   返回顶部   关闭窗口Tags:asp|js|二级联动  
参与评论
网友评论列表
© CopyRight 2008 Pcook.com.cn, Inc.All Rights Reserved.
Powered by:laoy8 Design by:Pcook 沪ICP备08004247号