触摸屏租赁
Touch screen rental
广告机租赁
Advertising rental
机器人租赁
Robot leasing
 当前位置:首页 > > ASP三级联动,实现与数据库连接的下拉菜单控制下拉菜单

ASP三级联动,实现与数据库连接的下拉菜单控制下拉菜单,无刷新

<%
Option Explicit
'数据库:
'location
'表1 loaction 所在的市 表
'   字段
'   loactionid  (主键)
'   loactionname 名字
'表2 district  所在的县 表
'   字段
'   locationid (主键)
'    districtid
'    districtname
'表3 village  所在的乡镇 表
'   字段
'   districtid (主键)
'   villageid
'   villagename
%>
<html>
<head>
<title>List</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%
dim conn
dim rs
dim sql
dim count
dim rs1
dim sql1
dim rs2
dim sql2
dim count2
dim connstr

connstr="DBQ="+server.mappath("db11.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
sql = "select * from district order by locationid asc"
set rs = conn.execute(sql)

%>
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
        <%
        count = 0
        do while not rs.eof
        %>
subcat[<%=count%>] = new Array("<%=trim(rs("districtname"))%>","<%= trim(rs("locationid"))%>","<%= trim(rs("districtid"))%>");
        <%
        count = count + 1
        rs.movenext
        loop
        rs.close
        set rs=nothing
        %>
onecount=<%=count%>;

function changelocation(locationid)
    {
        document.myform.smalllocation.length = 0;
     document.myform.dlmc0.length = 0;
        document.myform.dlmc0.options[0] = new Option('==请选择乡镇==','');
      var locationid=locationid;
      var i;
        document.myform.smalllocation.options[0] = new Option('==请选择县==','');
      for (i=0;i < onecount; i++)
        {
            if (subcat[i][1] == locationid)
            {
        document.myform.smalllocation.options[document.myform.smalllocation.length] = new Option(subcat[i][0], subcat[i][2]);
            }       
        }
       
    }   
</script>

 


<%sql2 = "select * from village order by districtid asc"
set rs2 = conn.execute(sql2)
%>
<script language = "JavaScript">
var onecount2;
onecount2=0;
subcat2 = new Array();
        <%
        count2 = 0
        do while not rs2.eof
        %>
subcat2[<%=count2%>] = new Array("<%= trim(rs2("villagename"))%>","<%= trim(rs2("districtid"))%>","<%= trim(rs2("villagename"))%>");
        <%
        count2 = count2 + 1
        rs2.movenext
        loop
        rs2.close
        set rs2=nothing
        %>
onecount2=<%=count2%>;

function changelocation2(villageid)
    {
    document.myform.dlmc0.length = 0;

    var villageid=villageid;
    var j;
    document.myform.dlmc0.options[0] = new Option('==请选择乡镇==','');
    for (j=0;j < onecount2; j++)
        {
            if (subcat2[j][1] == villageid)
            {
                document.myform.dlmc0.options[document.myform.dlmc0.length] = new Option(subcat2[j][0], subcat2[j][2]);
            }       
        }
       
    }   
</script>
</head>
<body>

<form action="untitled1.asp" method="post" name="myform">
  <p><br>
    <select name="biglocation" onChange="changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value)" size="1">
      <option selected>请选择市</option>
      <%
       
        sql1 = "select * from loaction order by loactionname asc"
        set rs1 = conn.Execute (sql1)
        do while not rs1.eof
        %>
      <option value="<%=trim(rs1("loactionid"))%>"><%=trim(rs1("loactionname"))%></option>
      <%
        rs1.movenext
        loop
        rs1.close
        set rs1 = nothing
        conn.Close
        set conn = nothing
        %>
    </select>
  </p>
  <p>
    <select name="smalllocation" onChange="changelocation2(document.myform.smalllocation.options[document.myform.smalllocation.selectedIndex].value)">
      <option selected value="">==请选择县==</option>
    </select>
  </p>
  <p>
    <select name="dlmc0" size="1">
      <option value="-1" selected>==请选择乡镇==</option>
    </select>
  </p>
  <p> <br>
    <input type="submit" name="Submit" value="Submit">
    <br>
  </p>
</form>

</body>
</html>


工作室地址:重庆石桥铺电脑城B座 | 微信:z35544216 | 网址:www.35544216.com