回 帖 发 新 帖 刷新版面

主题:我头都大了,老师们请指点一下

请老师们看下列代码哪里有问题,为什么执行的时候总是会出现下面的情况:
在左侧下拉菜单(categoryid)里选择大类后,与其对应的小类本来应该出现在右侧的菜单(sortsid)里,但是它却出现在了左侧的大类下拉菜单(categoryid),请教老师原因是什么?




          <tr> 
            <td width="5%">选择分类: </td>
            <td> <%
rs.open "select * from category order by categoryorder",conn,1,1
if rs.eof and rs.bof then
response.write "请先添加商品大类。"
response.end
else
%> <select name="categoryid" size="1" id="categoryid" onChange="changelocation(document.myform.categoryid.options[document.myform.categoryid.selectedIndex].value)">
                <option selected value="<%=rs("categoryid")%>"><%=trim(rs("category"))%></option>
                <%      
 dim selclass
 selclass=rs("categoryid")
 rs.movenext
 do while not rs.eof
%>
                <option value="<%=rs("categoryid")%>"><%=trim(rs("category"))%></option>
                <%
 rs.movenext
 loop
end if
rs.close
%>
  </select>
      小类: 
   <select name="sortsid">
  <%rs.open "select * from sorts where parentid="&amp;selclass ,conn,1,1
if not(rs.eof and rs.bof) then
%>
                <option selected value="<%=rs("sortsid")%>"><%=rs("category")%></option>
                <% rs.movenext
do while not rs.eof%>
                <option value="<%=rs("sortsid")%>"><%=rs("category")%></option>
                <% rs.movenext
loop
end if[em8]

回复列表 (共4个回复)

沙发

onChange="changelocation(document.myform.categoryid.options[document.myform.categoryid.selectedIndex].value
改成
 onChange="changelocation(document.myform.sortsid.options[document.myform.sortsid.selectedIndex].value
试试

板凳


老师,虽然不出现这种现象了,但是为什么我选择大类时,相对应的的小类一栏中不出现小类内容呢?

3 楼

changelocation
需要看一下这个函数

4 楼

函数是这样的.
function changelocation(locationid)
    {
    document.myform.categoryid.length = 0; 

    var locationid=locationid;
    var i;
    for (i=0;i < onecount; i++)
        {
            if (subcat[i][1] == locationid)
            { 
             document.myform.categoryid.options[document.myform.categoryid.length] = new Option(subcat[i][0], subcat[i][2]);
            }        
        }

我来回复

您尚未登录,请登录后再回复。点此登录或注册