<!--#include file="conn.asp"-->
<%dim count
set rs=server.createobject("adodb.recordset")
rs.open "select * from [class_menu] order by class_order ASC",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("class_name"))%>","<%= rs("id")%>","<%=rs("class_id_1")%>");
<%
count = count + 1
rs.movenext
loop
rs.close
%>
onecount=<%=count%>;
function changelocation(locationid)
{
document.myform.class2id.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][2] == locationid)
{
document.myform.class2id.options[document.myform.class2id.length] = new Option(subcat[i][0], subcat[i][1]);
changelocation2(document.myform.class2id.options[document.myform.class2id.selectedIndex].value)
}
}
}
function changelocation2(locationid)
{
document.myform.class3id.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][2] == locationid)
{
document.myform.class3id.options[document.myform.class3id.length] = new Option(subcat[i][0], subcat[i][1]);
}
}
}
</script>
<script language="JavaScript">
function CheckForm()
{
if(document.myform.class1id.value<=0) {
document.myform.class1id.focus();
alert("请选择市级分类!");
return false;
}
if(document.myform.class2id.value<=0) {
document.myform.class2id.focus();
alert("请选择地区分类!");
return false;
}
}
</script>
</head>
<body>
<form name="myform" method="post" action="product_save.asp?action=add" onSubmit="return CheckForm();" enctype="multipart/form-data">
<table width="70%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="35" align="center" class="14p"><strong>选择分类</strong></td>
</tr>
</table>
<table width="70%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="22"> </td>
</tr>
</table>
<table width="70%" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td align="center">
<%
rs.open "select * from [class_menu] where class_id_1='0' order by class_order ASC",conn,1,1
if rs.eof and rs.bof then
response.write "请先添加栏目。"
response.end
else
%>
市区分类:
<select name="class1id" size="1" id="class1id" onChange="changelocation(document.myform.class1id.options[document.myform.class1id.selectedIndex].value)" class="wenbenkuang">
<option selected>选择市级分类</option>
<option value="<%=rs("id")%>"><%=trim(rs("class_name"))%></option>
<%
dim selclass
selclass=rs("id")
rs.movenext
do while not rs.eof
%>
<option value="<%=rs("id")%>"><%=trim(rs("class_name"))%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select>
地区分类:
<select name="class2id" size="1" id="class2id" onChange="changelocation2(document.myform.class2id.options[document.myform.class2id.selectedIndex].value)" class="wenbenkuang">
<option selected>选择地区分类</option>
</select>
县级分类:
<select name="class3id" class="wenbenkuang">
<option selected>选择县级分类</option>
</select>
<SCRIPT language=JavaScript type=text/JavaScript>
for(i=0;i<document.myform.class1id.length;i++)
{
if(document.myform.class1id.options[i].value==<%=class1id%>)
{
document.myform.class1id.options[i].selected = true;
}
}
changelocation(document.myform.class1id.options[document.myform.class1id.selectedIndex].value);
for(i=0;i<document.myform.class2id.length;i++)
{
if(document.myform.class2id.options[i].value==<%=class2id%>)
{
document.myform.class2id.options[i].selected = true;
}
}
changelocation2(document.myform.class2id.options[document.myform.class2id.selectedIndex].value);
for(i=0;i<document.myform.class3id.length;i++)
{
if(document.myform.class3id.options[i].value==<%=class3id%>)
{
document.myform.class3id.options[i].selected = true;
}
}
</SCRIPT> </td>
</tr>
</table>
</form>
</TD>
</TR>
<TR>
<TD class=forumrow>
</TD>
</TR>
</TABLE>
<br>
<!-- -----------------------1----------------------- -->
<br>
</body>
</html>
<!--#include file="copyright.asp"-->
3 个解决方案
#1
哪位大神,跪求如何修改???小弟在线等。。。
#2
每次选择一级的时候清空2,3级的项在判断是否有子项,有再添加
function changelocation(locationid)
{
document.myform.class2id.length = 0;
document.myform.class3id.length = 0;/////////////
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][2] == locationid)
{
document.myform.class2id.options[document.myform.class2id.length] = new Option(subcat[i][0], subcat[i][1]);
changelocation2(document.myform.class2id.options[document.myform.class2id.selectedIndex].value)
}
}
}
function changelocation(locationid)
{
document.myform.class2id.length = 0;
document.myform.class3id.length = 0;/////////////
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][2] == locationid)
{
document.myform.class2id.options[document.myform.class2id.length] = new Option(subcat[i][0], subcat[i][1]);
changelocation2(document.myform.class2id.options[document.myform.class2id.selectedIndex].value)
}
}
}
#3
谢谢版主。真的可以了。。。灰常灰常感谢。。
#1
哪位大神,跪求如何修改???小弟在线等。。。
#2
每次选择一级的时候清空2,3级的项在判断是否有子项,有再添加
function changelocation(locationid)
{
document.myform.class2id.length = 0;
document.myform.class3id.length = 0;/////////////
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][2] == locationid)
{
document.myform.class2id.options[document.myform.class2id.length] = new Option(subcat[i][0], subcat[i][1]);
changelocation2(document.myform.class2id.options[document.myform.class2id.selectedIndex].value)
}
}
}
function changelocation(locationid)
{
document.myform.class2id.length = 0;
document.myform.class3id.length = 0;/////////////
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][2] == locationid)
{
document.myform.class2id.options[document.myform.class2id.length] = new Option(subcat[i][0], subcat[i][1]);
changelocation2(document.myform.class2id.options[document.myform.class2id.selectedIndex].value)
}
}
}
#3
谢谢版主。真的可以了。。。灰常灰常感谢。。