两个下拉框联动问题,如何实现选第一个下拉框后,第二个里面的也跟着动, 代码错误在哪里?
两个下拉框联动问题,如何实现选第一个下拉框后,第二个里面的也跟着动,第一个下拉框是大的分类,第二个是每个分类的产品下面的代码,是实现不了联动,变换第一个下拉框内容,第二个...
两个下拉框联动问题,如何实现选第一个下拉框后,第二个里面的也跟着动,
第一个下拉框是大的分类,第二个是每个分类的产品
下面的代码,是实现不了联动,变换第一个下拉框内容,第二个内容不变,不知道哪里有错误,请高手指点。
我的代码是
<script language="javascript" >
function funChange(){
var f = document.com;
if(f.code.value == "1"){
f.mei.options.length = 0;
for(var i=0;i<2;i++){
var option = document.createElement("option");
option.text = "class "+(i+1);
f.mei.options.add(option,i);
}
}
if(f.code.value == "2"){
f.mei.options.length = 0;
for(var i=0;i<2;i++){
var option = document.createElement("option");
option.text = "class "+(i+3);
f.mei.options.add(option,i);
}
}
if(f.code.value == "3"){
f.mei.options.length = 0;
for(var i=0;i<2;i++){
var option = document.createElement("option");
option.text = "class "+(i+5);
f.mei.options.add(option,i);
}
}
}
</script>
<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" style="border:1px solid #cccccc;" >
<tr>
<td width="100%" height="33" colspan="2" >
<div style=" padding-left:10px; color:#ff6633;">Product Search</div>
</td>
</tr>
<FORM METHOD="post" name="com" id="frmInput"ACTION="searchproduct.asp">
<tr>
<td width="35"><div style="padding-left:10px; ">Categories:</div></td>
<td height="50" align="left" >
<select name="code" onchange="funChange()">
<option selected="selected">Type</option>
<%set rs = server.CreateObject("adodb.recordset")
sql="select * from deeptree order by id desc"
rs.open sql,conn,1,1
%>
<% typeid=rs("id")
rs.movenext
while not rs.eof %>
<option value="<%=rs("id")%>"><%=left(rs("content"),10)%></option>
<%
rs.movenext
wend
rs.colose
%>
</select>
</td>
</tr>
<tr>
<td height="50" ></td>
<td align="left">
<select name="mei">
<%
set rss = server.CreateObject("adodb.recordset")
sql="select * from product where typeid="&typeid
rss.open sql,conn,1,1
while not rss.eof
%>
<option value="<%=rss("id")%>"><%=left(rss("productname"),10)%></option>
<%
rss.movenext
wend
%>
</select>
</td>
</tr>
<tr>
<td height="50" ></td>
<td align="left"> <INPUT TYPE="image" src="images/search.gif"></td>
</tr>
</FORM>
</table>
代码写错了,请看下面更换后的,如果您的建议,帮我解决了,一样会给你分数的,上面的是静态的可以用,第二个代码是动态的,要用到动态的,请赐教, 展开
第一个下拉框是大的分类,第二个是每个分类的产品
下面的代码,是实现不了联动,变换第一个下拉框内容,第二个内容不变,不知道哪里有错误,请高手指点。
我的代码是
<script language="javascript" >
function funChange(){
var f = document.com;
if(f.code.value == "1"){
f.mei.options.length = 0;
for(var i=0;i<2;i++){
var option = document.createElement("option");
option.text = "class "+(i+1);
f.mei.options.add(option,i);
}
}
if(f.code.value == "2"){
f.mei.options.length = 0;
for(var i=0;i<2;i++){
var option = document.createElement("option");
option.text = "class "+(i+3);
f.mei.options.add(option,i);
}
}
if(f.code.value == "3"){
f.mei.options.length = 0;
for(var i=0;i<2;i++){
var option = document.createElement("option");
option.text = "class "+(i+5);
f.mei.options.add(option,i);
}
}
}
</script>
<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" style="border:1px solid #cccccc;" >
<tr>
<td width="100%" height="33" colspan="2" >
<div style=" padding-left:10px; color:#ff6633;">Product Search</div>
</td>
</tr>
<FORM METHOD="post" name="com" id="frmInput"ACTION="searchproduct.asp">
<tr>
<td width="35"><div style="padding-left:10px; ">Categories:</div></td>
<td height="50" align="left" >
<select name="code" onchange="funChange()">
<option selected="selected">Type</option>
<%set rs = server.CreateObject("adodb.recordset")
sql="select * from deeptree order by id desc"
rs.open sql,conn,1,1
%>
<% typeid=rs("id")
rs.movenext
while not rs.eof %>
<option value="<%=rs("id")%>"><%=left(rs("content"),10)%></option>
<%
rs.movenext
wend
rs.colose
%>
</select>
</td>
</tr>
<tr>
<td height="50" ></td>
<td align="left">
<select name="mei">
<%
set rss = server.CreateObject("adodb.recordset")
sql="select * from product where typeid="&typeid
rss.open sql,conn,1,1
while not rss.eof
%>
<option value="<%=rss("id")%>"><%=left(rss("productname"),10)%></option>
<%
rss.movenext
wend
%>
</select>
</td>
</tr>
<tr>
<td height="50" ></td>
<td align="left"> <INPUT TYPE="image" src="images/search.gif"></td>
</tr>
</FORM>
</table>
代码写错了,请看下面更换后的,如果您的建议,帮我解决了,一样会给你分数的,上面的是静态的可以用,第二个代码是动态的,要用到动态的,请赐教, 展开
4个回答
2010-12-09
展开全部
刚才上面的代码粘贴错了,应该是修改这个代码,谢谢了
<%set rs=server.createobject("adodb.recordset")
sql = "select * from product "
rs.open sql,conn,1,1
%>
<script language =javascript>
var onecount;
subcat = new Array();
<%
count = 0
do while not rs.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rs("productname"))%>","<%= trim(rs("typeid"))%>");
<%
count=count+1
rs.movenext
loop
rs.close
%>
onecount=<%=count%>;
function changelocation(locationid)
{
document.form1.second_name.length = 1;
var locationid=locationid;
var i;
for (i=0;i < onecount; i )
{
if (subcat[i][1] == locationid)
{
document.form1.second_name.options[document.form1.second_name.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</script>
<form name="form1" method="post" action="Save_Second.asp">
<table width="600" height="93" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="218" height="29">所属类型:</td>
<td width="382">
<select name="Up_name" size="1" id="Up_name" onChange="changelocation(document.form1.Up_name.options[document.form1.Up_name.selectedIndex].value)">
<%
sql="select * from deeptree "
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1%>
<option selected value="<%=trim(rs("content"))%>"><%=trim(rs("content"))%></option>
<% typeid=rs("id")
rs.movenext
do while not rs.eof %>
<option value="<%=rs("content")%>"><%=rs("content")%></option>
<%rs.movenext
loop
rs.close
%>
</select>
<select name="second_name" size="1" id="second_name">
<%
sql="select * from product where typeid="&typeid
rs.open sql,conn,1,1
if not(rs.eof and rs.bof) then
%>
<option value="<%=rs("productname")%>"><%=rs("productname")%></option>
<% rs.movenext
do while not rs.eof%>
<option value="<%=rs("productname")%>"><%=rs("productname")%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select></td>
</tr>
<tr>
<td height="27">二级分类</td>
<td></td>
</tr>
<tr>
<td><div align="right">
<input type="submit" name="Submit" value="提交">
</div></td>
<td><input type="reset" name="Submit2" value="重置"></td>
</tr>
</table>
</form>
<%set rs=server.createobject("adodb.recordset")
sql = "select * from product "
rs.open sql,conn,1,1
%>
<script language =javascript>
var onecount;
subcat = new Array();
<%
count = 0
do while not rs.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rs("productname"))%>","<%= trim(rs("typeid"))%>");
<%
count=count+1
rs.movenext
loop
rs.close
%>
onecount=<%=count%>;
function changelocation(locationid)
{
document.form1.second_name.length = 1;
var locationid=locationid;
var i;
for (i=0;i < onecount; i )
{
if (subcat[i][1] == locationid)
{
document.form1.second_name.options[document.form1.second_name.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</script>
<form name="form1" method="post" action="Save_Second.asp">
<table width="600" height="93" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="218" height="29">所属类型:</td>
<td width="382">
<select name="Up_name" size="1" id="Up_name" onChange="changelocation(document.form1.Up_name.options[document.form1.Up_name.selectedIndex].value)">
<%
sql="select * from deeptree "
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1%>
<option selected value="<%=trim(rs("content"))%>"><%=trim(rs("content"))%></option>
<% typeid=rs("id")
rs.movenext
do while not rs.eof %>
<option value="<%=rs("content")%>"><%=rs("content")%></option>
<%rs.movenext
loop
rs.close
%>
</select>
<select name="second_name" size="1" id="second_name">
<%
sql="select * from product where typeid="&typeid
rs.open sql,conn,1,1
if not(rs.eof and rs.bof) then
%>
<option value="<%=rs("productname")%>"><%=rs("productname")%></option>
<% rs.movenext
do while not rs.eof%>
<option value="<%=rs("productname")%>"><%=rs("productname")%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select></td>
</tr>
<tr>
<td height="27">二级分类</td>
<td></td>
</tr>
<tr>
<td><div align="right">
<input type="submit" name="Submit" value="提交">
</div></td>
<td><input type="reset" name="Submit2" value="重置"></td>
</tr>
</table>
</form>
展开全部
你写的比较乱,看不清,你可以到一些网站源码网站上去找的,有这样的代码的,
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
嘿嘿……
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2010-12-23
展开全部
这里有一个多级联动select
你可以参考一下
你可以参考一下
参考资料: http://www.blueidea.com/common/shoutbox/redir.asp?8=b&id=11685
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询