懂ASP中的复选框的用法的大侠请进?(100分)

F

flyso

Unregistered / Unconfirmed
GUEST, unregistred user!
从库中取得用户名,使用复选框的形式,每个用户名前一个复选框,
并把复选框默认为选中[checked] 如下:
<input name="check" type="checkbox" id="check" value="<%=rs("name")%>" checked>
当选中的时候,我就把这些用户名的库中的共同字段status都分别改为1
,把取消的没有选中的Status设为0,
请问我该如何实现?
 
你是想即时的修改数据库status字段对吗?
这样是不行的,因为你没有处理修改的asp页面
你必须另外写一个处理页面来接收提交的信息
 
是的,我是写了一个check页面 <form name="form1" method="post" action="check.asp">
但是不知从何入手,写了一些,但始终不能实现功能,请大侠指点...
 
<form action="">
<input name="checkbox_1" type="checkbox" value="sdsa">
</form>
checkbox_1=Request.Form("input_1")
if checkbox_1<>"" then
rs("status")=1
else
rs("status")=0
end if
 
我按你的方法做了,但出错了啊?
<!--#include file="conn.asp" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
<title>...</title>
</head>
<% sql="select * FROM [aaa]"
rs.Open sql, conn, 1, 1
%>
<%
check=Request.Form("check")
if check<>"" then
rs("status")=1
else
rs("status")=0
end if
%>
<body>
</body>
</html>
 
被选中的checkbox传过去的是一个字符串数组,是以逗号“,”隔开的
没别选中的则值value是不会传过去的
你用Request.Form("check")接收到的值是这样的“id1,id2,id3....”
你在执行的时候用update table set status=1 where name in (这里写Request.Form("check"))
具体的语句自己多动手动脑筋去实践吧,我只给你说思路了
 
<%
for each check in request.form("check")
//这里check为某一个选中的check的value,其它的sql就自己写了
next
%>
 
大哥帮忙帮到底吧,现在锇晕了,实在想不出来了,总是出错,谢谢!
 
代码如下,现在只能在所有的钩去掉,才只是把第一个的status改为了0,而不是一一对应的关系了,就是csz说得那样的情况了,但是那代码我实在不能理解,我初学,请指点
<!--#include file="conn.asp" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
<title>...</title>
</head>
<% sql="select * FROM [aaa]"
rs.Open sql, conn, 1, 2
%>
<%
for each check in request.form("check")
if check<>"" then
rs("STATUS")=1
rs.update
else
rs("STATUS")=0
rs.update
end if
next
%>
<body>
</body>
</html>
 
你的意思是這樣嗎? 暈死了,我也不知是不是這樣,我也是菜鳥一個,亂寫一通了
<form name="form1" method="post" action="check.asp">
<input type="checkbox" name="status" value="on">
<input type="submit" value=" 添 加 " name="cmdok">
</form>
<%
if request.form("status")="on" then
status=1
else
status=0
end if
set rs=server.createobject("adodb.recordset")
sql="select * from 表1 where (id is null)"
rs.open sql,conn,1,3
rs.addnew
rs("status")=status
rs.update
rs.close
set rs=nothing
conn.Close
set conn=nothing
%>
 
不对啊,运行后插了一条空记录
 
dd=request.form("checkbox")
if len(trim(dd))<>0 then
if dd="1" then
set rs=server.createobject("adodb.recordset")
sql="select * from 表1 where (id is null)"
rs.open sql,conn,1,3
rs.addnew
rs("status")=status
rs.update
rs.close
set rs=nothing
conn.Close
set conn=nothing
end if
end if
你现判断是否选中再判断是否你要的值。
 
因为你是多个checkbox 它的name是相同的所以你应该要搜索一遍:
for each dd in request.form("checkbox")
if len(trim(dd))<>0 then
if dd="1" then
set rs=server.createobject("adodb.recordset")
sql="select * from 表1 where (id is null)"
rs.open sql,conn,1,3
rs.addnew
rs("status")=dd
rs.update
rs.close
set rs=nothing
conn.Close
set conn=nothing
end if
end if
next
 
不行啊,修改后的代码如下:
<%
for each dd in request.form("check")
if len(trim(dd))<>0 then
if dd="1" then
set rs=server.createobject("adodb.recordset")
sql="select * from aaa where (id is null)"
rs.open sql,conn,1,3
rs.addnew
rs("status")=dd
rs.update
rs.close
set rs=nothing
conn.Close
set conn=nothing
end if
end if
next

%>
还有这里根本就没有stutus为0的判断
 
怎么还没弄明白啊
<%
for each check in request.form("check")
response.write check //你会发现只有check选中才会传到asp中
next
%>
SQL语句可以这么写
<%
conn.execute("update aaa set state=1 where name in "&amp;request.form("check"));
conn.execute("update aaa set state=0 where name not in "&amp;request.form("check"));
%>
 
还是不行,不知道哪出错了,麻烦大侠再看看:
check.asp
<!--#include file="conn.asp" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
<title>...</title>
</head>
<%
for each check in request.form("check")
response.write check //只有check选中才会传到asp中
next
%>
<%
conn.execute("update aaa set state=1 where name in "&amp;request.form("check"))
conn.execute("update aaa set state=0 where name not in "&amp;request.form("check"))
%>

<body>
</body>
</html>
index.asp
......
<input name="check" type="checkbox" id="check" value="<%=trim(rs("name"))%>" checked>
......
 
错误类型:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]第 1 行: '大树' 附近有语法错误。
/166pass/check.asp, 第 14 行

浏览器类型:
Mozilla/4.0 (compatible;
MSIE 6.0;
Windows NT 5.1)
网页:
POST 308 ??? /166pass/check.asp
POST Data:
check=%B4%F3%CA%F7&amp;check=%B1%F9%CC%C7&amp;check=%F1%D2%C1%A6&amp;check=%D7%AF%D0%A1%B9%F3&amp;check=%B8%FB%C1%F7&amp;check=%C2%DE%B0%AE%C3%F1&amp;check=%BA%FA%BA%A3%D1%E0&amp;check=%D0%A1%F2%DF%F2%D1&amp;check=%C1%F5&amp;check=%CD%F . .
 
你的这个问题是没有办法啦,我也碰到过,没办法解决,最后我是用JAVASCRIPT和隐藏域搞定了。
原理:
JAVASCRIPT可以判断一个checkbox是否已经给点了,如果当一个checkbox给点了,那么相应的隐藏域就设为1(默认值为0).这个判断放在form的onsubmit事件里执行。
 
能把程序给研究一下吗
还有我已经将接收的数组串分开了,一个个的都输出了来了,但是似乎还是无法实现,郁闷
代码如下:
check.asp
<!--#include file="conn.asp" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
<title>...</title>
</head>
<% sql="select * FROM [aaa]"
rs.Open sql, conn, 1, 2
%>
<%
for i=1 to request("check").count
check=trim(request("check")(i))
response.write check
if check<>" " then

rs("STATUS")=1

else
rs("STATUS")=0
end if
%>
<br>
<%
next
%>
<%

'for each check in request.form("check")
'if check<>"" then
'rs("STATUS")=1
'rs.update
'else
'rs("STATUS")=0
'rs.update
'end if
'next
%>


<body>
</body>
</html>
index.asp
...
<input name="check" type="checkbox" id="check" value="<%=trim(rs("name"))%>" checked>...
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
742
DelphiTeacher的专栏
D
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
顶部