一个下拉列表框的问题!

bujingyu 2004-12-08 09:13:12
<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#94b6cf" >
<tr class="tr1">
<td width="60%" align="center" height="25" bgcolor="#F4F9F9">

‘此处从数据库中读出用户的id和姓名,并列在下拉列表框中,当我选中任意一个姓名时,可以对相应的人员进行编辑,但id却不能够动态的变化,不知道该如何解决?

<select name="userlist">
<% set rslist=server.CreateObject("adodb.recordset")
sqllist="select id,姓名 from userinfo"
rslist.open sqllist,conn,1,1
for j=1 to rslist.recordcount
if not rslist.eof then
response.Write "<option value="&rslist("id")&">"&rslist("姓名")&"</option>"
end if
rslist.movenext
next
%>
</select> </td>
<td align="center"><form action="personal.asp" method="post" class="form1"><input type="submit" name="Submit" value="提交" class="button1"></form>

’关键是下面的部分,当选中用户名后,id该如何跟着动态变化??求大家帮忙!!是不是我写的语句有问题??

<%
response.write"<a href='personal.asp?act=edit&id="&request("userlist")&"'>编辑</a>"
'response.write"<a href='javascript:confirmDel("&requset("id")&")'>删除</a>"
%>
</td></tr>
</table>
...全文
97 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
dafeifei 2004-12-08
用用javascript
回复
zlj113 2004-12-08
<script language="javascript">
function test(ID)
{
//alert (ID);
document.location.href = "personal.asp?id="+ID;


}
function del(ID)
{
if (confirm('你真的要删除所ID\n\n是否确定?')){
document.location.href = "del.asp?id="+ID;

}
}
</script>
<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#94b6cf" >
<tr class="tr1">
<td width="60%" align="center" height="25" bgcolor="#F4F9F9">

<form name="form1" action="personal.asp" method="post" class="form1">
<select name="userlist" >
<option value="11">11</option>
<option value="2">12</option>
<option value="3">3</option>
<option value="4">4</option>
</select>

<input type="submit" name="Submit" value="提交" class="button1"></form> </td>
<td align="center">


<a href="#" onclick="test(document.form1.userlist.options[document.form1.userlist.selectedIndex].value)">编辑</a>|<a href="#" onclick="del(document.form1.userlist.options[document.form1.userlist.selectedIndex].value)">删除</a>


</tr>
</table>
回复
chf99cn 2004-12-08
<script language=javascript>
<%
dim RSconn
s="未毕业"
Set RSconn = Server.CreateObject("ADODB.Recordset")
RSconn.open "SELECT distinct stclass,user_depart FROM class where user_memo='"& s &"' ORDER BY user_depart DESC", Conn, 0, 1
dim provinceName '省名
dim provinceList '记录所有的省名, 最后输出到JS里组成省名数组
dim cityList '记录某个省的所有城市名, 最后输出到JS里组成城市名数组
dim cityIndex 'JS的city数组名与省名下拉框的索引对应
cityIndex = 1
do while not RSconn.eof
if isEmpty(provincename) then
cityList = cityList & chr(34) & Trim(RSconn("stclass")) & chr(34) &","
provinceName = Trim(RSconn("user_depart"))
else
if provinceName<>Trim(RSconn("user_depart")) then
provinceList = provinceList & chr(34) & provinceName & chr(34) &","
if not isEmpty(cityList) then Response.write "var city"& cityIndex &_
" = ["& Left(cityList, Len(cityList)-1) &"];"& VBCrLf
'输出每个省所对应的城市名的列表并组成JS的数组, 数组形式参考下面的实例
cityIndex = cityIndex + 1
cityList = ""
end if
provinceName = Trim(RSconn("user_depart"))
cityList = cityList & chr(34) & Trim(RSconn("stclass")) & chr(34) &","
'将每个省里的所有城市名组成一串字串
end if
RSconn.movenext
loop

if not isEmpty(cityList) then
Response.write "var city"& cityIndex &" = ["& Left(cityList, Len(cityList)-1) &"];"& VBCrLf
end if
if not isEmpty(provinceName) then
provinceList = provinceList & chr(34) & provinceName & chr(34) &","
Response.write "var provinceName = ["& Left(provinceList, Len(provinceList)-1) &"];"
'输出省名字串并组成省名的JS数组, 形式见下实例
end if
RSconn.close : Set RSconn=nothing
%>
</script>
<form name=form1 method="POST" action="test.asp">
专 业:
<select name=province onchange="cityName(this.selectedIndex)">
<option value="">请选择专业</option>
</select>
<p>
班 级:
<select name=city>
<option value="">请选择班级</option>
</select>
</p>
<script language=javascript>
/* 若要直接看下拉框联动效果的话, 将这段被注释的代码起用, 且上面的那段ASP注释即可
var provinceName = ["浙江", "江苏", "安徽", "江西"];
var city1 = ["杭州", "宁波", "温州", "绍兴", "金华", "湖州"];
var city2 = ["南京", "苏州", "无锡", "常州", "镇江", "徐州"];
var city3 = ["合肥", "翕县", "黄山", "祁门", "休宁"];
var city4 = ["南昌", "九江", "赣州", "上饶", "新余", "景德镇"];
//你在ASP输出的页面里应该看到如上这般的JS数组, 能看到则表示成功
*/
function province()
{
var e = document.form1.province;
for (var i=0; i<provinceName.length; i++)
e.options.add(new Option(provinceName[i], provinceName[i]));
}
function cityName(n)
{
var e = document.form1.city;
e.options.length = 1;
if (n == 0) return;
var a = eval("city"+ n); //得到城市的数组名
for (var i=0; i<a.length; i++) e.options.add(new Option(a[i], a[i]));
}
window.attachEvent("onload", province); //初始时给省名下拉框赋内容
</script>
回复
uGain 2004-12-08
<%
response.write"<a href='personal.asp?act=edit&id="&request("userlist")&"'>编辑</a>"
'response.write"<a href='javascript:confirmDel("&requset("id")&")'>删除</a>"
%>
编辑的时候知道用&request("userlist"),怎么删除的时候就变成&request("id")了?
回复
zlj113 2004-12-08
呵呵,不懂楼主为什么要这样写呢,你把那表单提交后不就能取得ID了吗??
回复
qfacy 2004-12-08
建立个函数
function selected(req,reqvalue)
if req=reqvalue then
selected=" selected"
else
selected=""
end if
end function

<select name="userlist">
<% set rslist=server.CreateObject("adodb.recordset")
sqllist="select id,姓名 from userinfo"
rslist.open sqllist,conn,1,1
if request("userlist")="" then first=rslist("id")
if request("userlist")<>"" then first=request("userlist")
for j=1 to rslist.recordcount
if not rslist.eof then
response.Write "<option value="&rslist("id") selected(rs("id",first))&">"&rslist("姓名")&"</option>"
end if
rslist.movenext
next
%>
</select>
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2004-12-08 09:13
社区公告
暂无公告