日期:2009-08-24  浏览次数:20901 次

有一个应用,要求一个下拉列表(class1)的变化触发另一个依赖列表(class2)的变化。参照《下拉框连动(数据库版)》,有以下程序片段:

<%   sql = "select id, name, substring(id,1,2) bigclass from classone where type='1' order by id"

   set rs = session("conn").execute(sql)
%>

<script language="javascript">
   var onecount = 0;
   subcat = new array();    <---------提示:array 未定义------------

   <%    count = 0
   do while not rs.eof      <--------- rs 已经是前面定义的recordset
   %>
   subcat[<%=count%>] = new array("<%=trim(rs("name"))%>","<%=trim(rs("bigclass"))%>","<%=trim(rs("id"))%>");
   <%    count = count+1
      rs.movenext
      loop
      rs.close
      set rs = nothing
   %>
   onecount = <%=count%>

   function chgcls(){
      for (var i=document.search.class2.options.length; i>0; i--){
         document.search.class2.options[i]=null;
      }
      for (i = 0; i<onecount; i++){
         bigclass = "'"&subcat[i][1]&"'";
         if (document.search.class1.options[document.search.class1.selectedindex].value==bigclass){
         document.search.class2.options[document.search.class2.length]=new option(subcat[i,0],subcat[i,2]);
         }
      }
   }
</script>

下面是调用该函数的HTML语句:
。。。
<form id="search" name="search" method="post" action="query.ASP">
<select name="class1" size=1 width=16 onchange="chgcls(document.search.class1.options[document.search.class1.selectedIndex].value)">
   <%
   Response.Write "<option selected value=''></option>"
   sql="select id,name from classone where substring(id,3,1)='' order by id"            '取设备代码的前两位
     set menurs=session("conn").execute(sql)
     do while not menurs.eof
        Response.Write "<option value="&trim(menurs("id"))&">"&trim(menurs("name"))&"</option>"
        menurs.movenext
     loop
     menurs.close
     set menurs=nothing   
    %></select>

   <select name="class2" size=1 width=16>
   <option selected value=""></option>
   </select>
.....
</form>

问题1:我在加入下列JavaScript 后,“array 未