javascript 实现下拉列表连动,提示:Array not defined

发表于:2007-06-30来源:作者:点击数: 标签:
有一个应用,要求一个下拉列表(class1)的变化触发另一个依赖列表(class2)的变化。参照《下拉框连动( 数据库 版)》,有以下程序片段: % sql = select id, name, substring(id,1,2) bigclass from classone where type=@#1@# order by id set rs = session
有一个应用,要求一个下拉列表(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 未定义”不再出现,是否是JAVASCRIPT 本身的要求,还是与浏览器的版本有关?(我用IE4)
function array() {    
   this.length = array.arguments.length
   for (var i = 0; i< this.length; i++)      this[i+1] = array.arguments[i];   
}


问题2:但是却提示:
    document.search.class1.options[...].value 不是对象
    为什么?
.......

原文转自:http://www.ltesting.net