window对象execScript实现的级联下拉列表的核心代码

 <%
 Dim Con1,Rs
 Dim SQL,DSN
 Dim Array1()
 Set Con1=server.CreateObject("adodb.connection")
 Set Rs=server.CreateObject("adodb.recordset")
 DSN="driver={Microsoft Access Driver (*.mdb)};dbq=" &server.MapPath("User.mdb")
 Con1.Open DSN
 SQL="select * from Company order by CompanyID"
 Rs.Open SQL,Con1,3,2
 Rs.MoveFirst
 ReDim Array1(Rs.RecordCount-1)
 %>
 <table width="300" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td width="82">
            <select id="select1" name="select1">
                <option selected value="select<%=Rs("CompanyCode")%>"><%=Rs("CompanyName")%></option>
                <%
                'Array1数组存放CompanyCode字段值
                Array1(0)=Rs("CompanyCode")
                Rs.MoveNext
                Dim i
                For i=1 To Rs.RecordCount-1
                %>
                <option value="select<%=Rs("CompanyCode")%>"><%=Rs("CompanyName")%></option>
                <%
                Array1(i)=Rs("CompanyCode")
                Rs.MoveNext
                Next
                %>
            </select>
            <%
            Rs.Close
            %>
        </td>
        <td width="191">
        <%
        '将Department中对应数组Array1中的每个元素取出来
        For i=0 To UBound(Array1)
        SQL="select * from Department where DepartmentCode like '"&Array1(i)&"%'"
        Rs.Open SQL,Con1,3,2
        If Rs.RecordCount > 0 Then
        Rs.MoveFirst
        %>
        <select id="select<%=Array1(i)%>" style="display='none'" name="select<%=Array1(i)%>">
            <%Do While Not Rs.Eof%>
            <option value="<%=Rs("DepartmentName")%>"><%=Rs("DepartmentName")%></option>
            <%
            Rs.MoveNext
            Loop
            %>
        </select>
        <%
        End If
        Rs.Close
        Next
        %>
        </td>
    </tr>
 </table>
 <script language="vbscript">
<!--
    Dim obj,lastObj
    lastObj="select01"
    obj="select01"
    Window.execScript "select01.style.display='block'","vbs"
    Sub select1_onchange
        obj=select1.value
        If obj <> lastObj And IsObject(eval(obj)) Then 
            Window.execScript obj & ".style.display='block'","vbs"
            Window.execScript lastObj &".style.display='none'","vbs"
            Window.execScript "Department="&obj&".value","vbs"
            lastObj=select1.value
        End If
    End Sub
-->
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值