二级分类不存在就显示“无二级分类”如何修改?
求助各位:一个ASP后台,产品发布表单中的产品类别选择菜单,现在的效果是这样的,点选某个一级分类,如该类下有二级分类就显示出二级分类选项,如该类下无二级分类就显示一个空的菜单,我想改成这样:如某个一级分类下无二级分类,就显示一个“无二级分类”的菜单项,而不是一个空的菜单,怎样修改如下JS?
<script language = "javascript">
var i,j;
j=0;
goaler = new Array();
<%set rs_p=conn.execute("select * from p_class_small order by p_small_id")
if rs_p.eof then%>
goaler[0] = new Array("无分类","","");
<%else
i=0
do while not rs_p.eof%>
goaler[<%=i%>] = new Array("<%=rs_p("p_small_type")%>","<%=rs_p("p_type")%>");
<%rs_p.movenext
i=i+1
loop
end if
rs_p.close
%>
j=<%=i%>;
function changelocation(location_id)//传递一级分类的值,从而改变二级分类
{
document.form1.p_small_type.length = 0;
var p_type=location_id;
var i;
for (i=0;i < j; i++)
{
if (goaler[i][1] ==p_type)
document.form1.p_small_type.options[document.form1.p_small_type.length] = new Option(goaler[i][0],goaler[i][0]);
}
}
</script>
HTML表单中的select是这样的:
<select name="p_type" size="1" id="p_type" onChange="changelocation(document.form1.p_type.options[document.form1.p_type.selectedIndex].value)">
<%set rs=conn.execute("select p_id,p_type from p_class")
if rs.eof then%>
<option selected value="">无一级分类</option>
<%else%>
<option selected value="">一级分类</option>
<%do while not rs.eof
%>
<option value="<%=rs("p_type")%>"><%=rs("p_type")%></option>
<%rs.movenext
loop
end if%>
</select> <select name="p_small_type" >
<option selected value="">二级分类</option>
</select>