主题:  关联下拉选择框的问题

林易

职务:普通成员
等级:3
金币:1.0
发贴:750
#12004/8/26 19:11:41
有三个表shop_anclass,shop_nclass,xhclass,后两个表行依据shop_anclass生成,现在通过,读出shop_anclass表,在中改变,而改变后两个选择框中类容,shop_nclass,xhclass不相关,可以实现选择第一个下拉框第二个下拉框中的选项变化,但是第三个下拉框不变化,不知道问题在那里,仔细看是对javascript语句不懂,贴出代码忘高人指导,谢谢
 <!--#include file="conn.asp"-->

<html>
<head>
<title>西北工程机械网</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="../css.css" rel="stylesheet" type="text/css">
<style>
td{font-size:9pt;line-height:120%;color:#353535} 
body{font-size:9pt;line-height:120%} 

a:link          { color: #000000; text-decoration: none }
a:visited       { color: #000000; text-decoration: none }
a:active        { color: #000000; text-decoration: none }
a:hover         { color: #336699; text-decoration: none; position: relative; right: 0px; top: 1px }
</style>
</head>
<%dim count
set rs=server.createobject("adodb.recordset")
rs.open "select * from shop_Nclass order by Nclassidorder ",conn,1,1%>
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
<%
   count = 0
   do while not rs.eof 
%>
subcat[<%=count%>] = new Array("<%= trim(rs("Nclass"))%>","<%= rs("anclassid")%>","<%= rs("Nclassid")%>");
<%
        count = count + 1
        rs.movenext
        loop
        rs.close
%>
		
onecount=<%=count%>;

function changelocation(locationid)
    {
    document.myform.Nclassid.length = 0; 
    var locationid=locationid;
    var i;
    for (i=0;i < onecount; i++)
        {
            if (subcat[i][1] == locationid)
            { //这句不是很理解
             document.myform.Nclassid.options[document.myform.Nclassid.length] = new Option(subcat[i][0], subcat[i][2]);
             document.myform.xhclassid.options[document.myform.xhclassid.length] = new Option(subcat[i][0], subcat[i][2]);
           
			}        
        }
        
    }    
</script>
<body>

<table width="205" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
  <tr> 
    <form name="myform" method="post" action="saveaddbook.asp" >
      <td height="126" bgcolor="#FFFFFF">
<table width="201" border="0" align="center" cellpadding="2" cellspacing="0">
          <tr> 
            <td>交易类型:</td>
            <td width="62%"> <select name="fudongjia" size=1 class="wenbenkuang">
                <%set rs_s=server.createobject("adodb.recordset")
rs_s.open "select * from shop_fudong order by id ",conn,1,1
if rs_s.recordcount=0 then
response.write "请先添加交易类型!"
else
while not rs_s.eof
%>
                <option value=<%=rs_s("id")%> selected ><%=rs_s("shuoming")%></option>
                <%
rs_s.movenext
wend
end if%>
              </select></td>
          </tr>
          <tr> 
            <td width="38%">设备类型:</td>
            <td> <%
        rs.open "select * from shop_anclass order by anclassidorder",conn,1,1
	if rs.eof and rs.bof then
	response.write "请先添加栏目。"
	response.end
	else
%> <select name="anclassid" size="1" id="anclassid" onChange="changelocation(document.myform.anclassid.options[document.myform.anclassid.selectedIndex].value)" class="wenbenkuang">
                <option selected value="<%=rs("anclassid")%>"><%=trim(rs("anclass"))%></option>
                <%      dim selclass
         selclass=rs("anclassid")
        rs.movenext
        do while not rs.eof
%>
                <option value="<%=rs("anclassid")%>"><%=trim(rs("anclass"))%></option>
                <%
        rs.movenext
        loop
	end if
        rs.close
%>
              </select>
                </td>
          </tr>
          <tr> 
            <td width="38%">生产厂商:</td>
            <td><select name="Nclassid" class="wenbenkuang">
                <%rs.open "select * from shop_Nclass where anclassid="&selclass ,conn,1,1
if not(rs.eof and rs.bof) then
%>
                <option selected value="<%=rs("NclassID")%>"><%=rs("Nclass")%></option>
                <% rs.movenext
do while not rs.eof%>
                <option value="<%=rs("NclassID")%>"><%=rs("Nclass")%></option>
                <% rs.movenext
loop
end if
        rs.close
        'set rs = nothing
%>
              </select></td>
          </tr>
          <tr> 
            <td width="38%">设备型号:</td>
            <%response.Write("selclass")%>
            <td> <select name="xhclassid" class="wenbenkuang" id="xhcalss">
                <% rs.open "select * from xhclass where anclassid="&selclass ,conn,1,1
if not(rs.eof and rs.bof) then
%>
                <option  selected value="<%=rs("xhclassid")%>"><%=rs("xhclass")%></option>
                <% rs.movenext
do while not rs.eof%>
                <option value="<%=rs("xhclassid")%>"><%=rs("xhclass")%></option>
                <% rs.movenext
loop
end if
        rs.close
        set rs = nothing
%>
              </select></td>
          </tr>
          <tr> 
            <td width="38%">价格范围:</td>
            <td><select class=a name=select>
                <option value="kong" selected>请选择价格范围</option>
                <option>1万以下</option>
                <option>10-20万</option>
                <option>20万以上</option>
              </select></td>
          </tr>
          <tr align="center"> 
            <td height="18" colspan="2"> <INPUT class=button name=submit22232 type=submit value=点击查看结果> 
            </td>
          </tr>
        </table></td>
    </form>
  </tr>
</table>
<br>

</body>
</html>