一级分类变化自动更新二级分类下拉列表

'取子分类于rs1
dim count
set rs1=server.createobject("adodb.recordset")
sql = "select * from jxkhzbzzfl order by zzfl_id asc"
rs1.open sql,conn,1,1
'-----------------------------------------
'将子分类记录写入数组subcat(子类名、父ID、子ID
'-----------------------------------------
%>

<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();

<%count = 0
do while not rs1.eof %>
   subcat[<%=count%>] = new Array("<%= trim(rs1("zzfl_name"))%>","<%= trim(rs1("year"))%>","<%= trim(rs1("zzfl_id"))%>");
   <%count = count + 1
   rs1.movenext
loop
rs1.close
%>
//列出所有子分类于数组subcat中供后面使用
//var   subcat   =   new   Array();    
//subcat[0]   =   new   Array('10','1','=1')    
//subcat[1]   =   new   Array('10','2','=2')
 
//subcat[0][0]='10'   //rs1("zfl_name")
//subcat[0][1]='1'    //rs1("zzfl_id")
//subcat[0][2]='=1'   //rs1("zfl_id")

//subcat[1][0]='10'  
//subcat[1][1]='2'  
//subcat[1][2]='=2'
//.....


onecount=<%=count%>;


function changelocation(locationid)
{
    document.form.zzfl_id.length = 0;
    var locationid=locationid;
    var i;
    for (i=0;i < onecount; i++)
        {
            if (subcat[i][1] == locationid)//
            {
                document.form.zzfl_id.options[document.form.zzfl_id.length] = new Option(subcat[i][0], subcat[i][2]);
                //document.form.zzfl_id.length第一次为0,过出某大类的所有子类
            }       
        }
       
    }  
   
//      onchange="changelocation(this.options.selectIndex)"
//应该是onchange="changelocation(this.options.selectedIndex)"

//new option();应该是 new Option();//大写的O


//<select id="s">
//</select>
//var option = new Option( "abc", "2312" );
//document.all.s.options[0] = option;
//var option2 = new Option( "def", "2312" );
//document.all.s.options[1] = option2;
//Option是 select 中的选择项,str1 是页面中看到的描述,而str2是这一项的值,比如
//<option value="这里是str2">这里是str1</option>
//new option(); 一般用在动态生成选择项目
    
</script>

 

 

一级分类

<select name="my1" onChange="changelocation(document.form.my1.options[document.form.my1.selectedIndex].value)">
 <option value="2008" <%if myear="2008" then %>selected<%end if%>>2008</option>
 <option value="2009" <%if myear="2009" then %>selected<%end if%>>2009</option>

</select>

二级分类

<select name="zzfl_id">
   <%              
   set rs2=server.createobject("ADODB.recordset")
   rs2.open "select * from jxkhzbzzfl   where year='" & myear & "'",conn,1,1
   if rs2.eof then
   else
   do while not rs2.eof
   if cstr(rs2("zzfl_id"))=cstr(mzzfl_id) then
   %>
   
              <option value="<%=rs2("zzfl_id")%>" selected><%=rs2("zzfl_name")%></option>             
              <%else%>             
              <option value="<%=rs2("zzfl_id")%>" ><%=rs2("zzfl_name")%></option>
              <%end if
             
              rs2.movenext
     loop
     rs2.close
     set rs2=nothing
     end if
     %></select>

你可能感兴趣的:(下拉列表)