ASP编写select列表的问题。

我想要这样一个效果:
第一个select列表,比如有“图片新闻”,“通知公告”,“新闻动态”这三项。
我想要用户当且仅当选中“通知公告”的时候,出现另一个select列表。
在第一个列表value不是选中“通知公告”的时候,不要显示出另一个列表。

用JS,CSS,用双级联,用ajax都可以,只要能和ASP兼容编写的就行,给代码吧,简要说明一下。
能用再加分,分数绝对不是问题。在此先谢谢看题的各位啦!
semaly朋友提供的代码就是我想要的效果,但是我把第一个列表的列表项换成从数据库中读取后,第一个列表正常显示,但选中“通知公告”的时候新列表就不跳出来了,我有把if语句中的value值改成if(window.document.getElementById("1stSct").value=="通知公告")了,是不是还有什么细节要修改呢?
第一个列表从数据库读取,正常读取!但是选中“通知公告”不出现新列表了!
<form name="SelectEg" action="" method="post">
<select id="1stSct" name="1stSct" onChange="HinputSct();">
<%do while not rs.eof%>
<option value="<%=trim(rs("vName"))%>"><%=trim(rs("vName"))%></option>
<%
rs.movenext
loop%>
</select>
<div id="innerSct"></div>
</form>
麻烦再给看看!谢谢!

思路是应该通过onChange传递第一个select的值,然后根据值判断第二个select是否显示,document.getElementById("1stSct").value是读取不到select的选值的,正确如下:

<form name="SelectEg" action="" method="post">
<select id="1stSct" name="1stSct" onChange="HinputSct(this.options[this.selectedIndex].value);">
<%do while not rs.eof%>
<option value="<%=trim(rs("vName"))%>"><%=trim(rs("vName"))%></option>
<%
rs.movenext
loop%>
</select>

<!--第二个select-->

<select id="select2" name="select2" style="display:none">
<option value="">第二个select</option>
</select>
</form>

<script type="text/javascript">
function HinputSct(svalue) //这里是关键,要加个变量,定义select传递过来的值
{
if (svalue=='通知公告')
{
document.getElementById('select2').style.display="Block";
return false;
}
else
{
document.getElementById('select2').style.display="none";
return false;
}
}
</script>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-01-07
<form name="form" action="ProductSearchList.asp" method="get">
<table border="0" id=table1 width="100%" cellpadding="0" style="border-collapse: collapse" bordercolor="#C0C0C0" height="33" cellspacing="0" align="center">
<tr>
<td class="TopSearch" height="17" valign="middle" width="59%" align="right">
<input type="text" name="KeyWord" size="20">
<%dim count
set rs=server.createobject("adodb.recordset")
rs.open "select * from cn_ProductsType order by orderID",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("name"))%>","<%= rs("fatherID")%>","<%= rs("ID")%>");
<%
count = count + 1
rs.movenext
loop
rs.close
%>
onecount=<%=count%>;
function changelocation(locationid)
{
document.form.SearchSid.length = 0;

var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.form.SearchSid.options[document.form.SearchSid.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</script>
<select name="SearchBid" size="1" id="SearchBid" onChange="changelocation(document.form.SearchBid.options[document.form.SearchBid.selectedIndex].value)">
<option selected value="0">选择大类</option>
<%
rs.open "select * from cn_ProductsType where fatherID=0 and ctid=539 order by orderID",conn,1,1
%>
<option value="<%=rs("id")%>"><%=trim(rs("name"))%></option>
<%
dim selclass
selclass=rs("id")
rs.movenext
do while not rs.eof
%>
<option value="<%=rs("id")%>"><%=trim(rs("name"))%></option>
<%
rs.movenext
loop
rs.close
set rs=nothing
%>
</select>
<select name="SearchSid" >
<option selected value="0">选择小类</option>
<%
set rs=server.CreateObject ("adodb.recordset")
if request("SearchBid")="" then
rs.open "select * from cn_ProductsType where fatherID<>0 and (fatherID is null)" ,conn,1,1
else
rs.open "select * from cn_ProductsType where fatherID<>0 and fatherID="&request("SearchBid")&"" ,conn,1,1
end if
do while not rs.eof%>
<option value="<%=rs("fatherID")%>" <%if trim(request("SearchBid"))=trim(rs("fatherID")) then%>selected<%end if%>><%=rs("name")%></option>
<% rs.movenext
loop
rs.close
set rs=nothing
%>
</select>
<input type="submit" value=" 搜 索 " name="B1">
</td>
</tr>
</table>
</form>

涉及到选择第一个,会调出第二个级联的.我一直用这个.希望对你有参考.
第2个回答  2010-01-06
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<script language="javascript">
function HinputSct()
{
var InnerEg;
InnerEg="新选项:<br /><select name='NewInput' action='' method='post'><option value='4'>选项4</option><option value='5'>选项5</option><option value='6'>选项6</option>";
if(window.document.getElementById("1stSct").value==2)
{
window.document.getElementById("innerSct").innerHTML=InnerEg;
}
else
{
window.document.getElementById("innerSct").innerHTML="";
}
}
</script>
<form name="SelectEg" action="" method="post">
<select id="1stSct" name="1stSct" onchange="HinputSct();">
<option value="1">图片新闻</option>
<option value="2">通知公告</option>
<option value="3">新闻动态</option>
</select>
<div id="innerSct"></div>
<input type="submit" value="Commit" />
</form>
</BODY>
</HTML>
第3个回答  2010-01-07
<form id="form1" name="form1" method="post" action="">
<select id="sel1" name="sel1" onchange="changeSel1();">
<option value="1">图片新闻</option>
<option value="通知公告">通知公告</option>
<option value="3">新闻动态</option>
</select>
<select id="sel2" name="sel2">
<option value="1">选项1</option>
<option value="2">选项2</option>
<option value="3">选项3</option>
</select>
</form>
<script language="javascript">
function changeSel1(){
if(form1.sel1.value=="通知公告"){
form1.sel2.style.display="none";
}
else{
form1.sel2.style.display="";
}
}
</script>
第4个回答  2010-01-08

if(window.document.getElementById("1stSct").value=="通知公告")

改成:
if(document.getElementById("1stSct").options.value=="通知公告")