关于select动态赋值的问题
我在网页上有两个列表框,第二个列表框B根据第一个列表框A的内容变化而变化。
两个列表框的内容都是从数据库里取值的,select * from test where id="abc",abc的就是A的值。请问如何通过A的onchange事件对列表框B进行赋值。我看了一些商业网站上的源代码,都是用过form的submit来进行,但没有详细的程序,如果有请大家推荐一下
问题点数:80、回复次数:4Top
1 楼net_lover(【孟子E章】)回复于 2003-06-04 08:18:29 得分 10
用xmlhttp啊Top
2 楼lqflsh(不要让困难成为理由)回复于 2003-06-04 08:21:26 得分 5
就是2级联动菜单。
这种贴子老多了。
收一下,一大堆。Top
3 楼gq(游子)回复于 2003-06-04 08:21:50 得分 35
一个数据库的例子:
<%
set cnn=server.CreateObject ("adodb.connection")
set rs=server.createobject("adodb.recordset")
cnn.open application("connectionstring")
%>
<script LANGUAGE="javascript">
<!--
var onecount;
onecount=0;
subcat = new Array();
<%
strsql = "select * from tblbureau where 1=1 "
if session("middle_bureau")<>"" then
strsql = strsql & " and middle_bureau='" & session("middle_bureau") & "'"
end if
if session("essential_bureau")<>"" then
strsql = strsql & " and essential_bureau='" & session("essential_bureau") & "'"
end if
set rs =cnn.execute(strsql)
dim i
i=0
do while not rs.eof %>
subcat[<%=i%>] = new Array("<%=rs("essential_bureau")%>","<%=rs("middle_bureau")%>","<%=rs("essential_bureau")%>");<%
i=i+1
rs.movenext
loop
%>
onecount=<%=i%>;
function changelocation(locationid)
{
document.frmsetup.essential_bureau.length = 0;
var locationid=locationid;
var i;
document.frmsetup.essential_bureau.options[0] = new Option('请选择','');
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.frmsetup.essential_bureau.options[document.frmsetup.essential_bureau.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
//-->
</script>
<form name=frmsetup>
<tr class=tb2>
<td width="15%" class=t1> 所在区</td>
<td width="35%" class=t1> <select size="1" name="settle_region" class=f1 onChange="changelocation(document.frmsetup.settle_region.options(document.frmsetup.settle_region.selectedIndex).value)">
<option value="">请选择</option>
<option value="罗湖">罗湖</option>
<option value="福田">福田</option>
<option value="南山">南山</option>
<option value="盐田">盐田</option>
<option value="宝安">宝安</option>
<option value="龙岗">龙岗</option>
</select>
</td>
<td width="15%" class=t1> 所在所</td>
<td width="35%" class=t1> <select size="1" name="essential_bureau" class=f1>
<option value="">请选择</option>
</select>
</td>
</tr>
<script LANGUAGE="javascript">
<!--
changelocation(document.frmsetup.settle_region.options(document.frmsetup.settle_region.selectedIndex).value)
//-->
</script>
</form>Top
4 楼lsrzm(Michale Lee)回复于 2003-06-04 08:49:25 得分 30
我这里有一个例子,包括数据库,需要的话给我发消息Top



