关闭

二级连动

380人阅读 评论(0) 收藏 举报

//以下是二级联动下拉代码
<%
      sql = "select distinct subject,userid from exam_database order by subject"
      set rs=server.createobject("adodb.recordset")
      rs.open sql,conn,3,2
%>
subcat = new Array();
allsub = new Array();
      <%
        do while not rs.eof
      %>
subcat[<%=counter%>] = new Array("<%= trim(rs("subject"))%>","<%= trim(rs("userid"))%>","<%= trim(rs("subject"))%>");
      <%
        counter = counter + 1
        rs.movenext
        loop
        rs.close:set rs=nothing
  
  sql="select distinct subject,userid from exam_database where userid='1' or userid='"&user&"' order by subject"
  set rs=server.createobject("adodb.recordset")
  rs.open sql,conn,3,2
  do while not rs.eof
      %>
allsub[<%=allcount%>] = new Array("<%= trim(rs("subject"))%>","<%= trim(rs("subject"))%>");
      <%
     allcount = allcount + 1
        rs.movenext
        loop
        rs.close:set rs=nothing
      %>

function changelocation(locationid)
{
    var i,counter,allcount,locationid;
 counter=<%=counter%>
 allcount=<%=allcount%>
 locationid=locationid;
 document.subjectform.subject.length = 1;
 if (locationid=="all")
 {
   for (i=0;i < allcount; i++)
        {
            document.subjectform.subject.options[document.subjectform.subject.length] = new Option(allsub[i][0], allsub[i][1]);
        }
 }
 else
 {
   for (i=0;i < counter; i++)
        {
            if (subcat[i][1] == locationid)
            {
                document.subjectform.subject.options[document.subjectform.subject.length] = new Option(subcat[i][0], subcat[i][2]);
            }       
        }
 }
}


<select name="database" onChange="changelocation(document.subjectform.database.options[document.subjectform.database.selectedIndex].value)">
              <option selected>--请选择--</option>
     <option value="all">所有</option>
     <option value="1">系统</option>
     <option value="<%=user%>">我的</option>
            </select>


       <option value="**">**</option>

</select> 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:38920次
    • 积分:463
    • 等级:
    • 排名:千里之外
    • 原创:11篇
    • 转载:4篇
    • 译文:0篇
    • 评论:2条
    最新评论