onclick事件更改数据库信息的实现?

siyuzhang 2004-10-28 11:18:51
把数据库里的数据以TEXT格式列出来,前面放置一个复选框,当复选框选定表示该数据修改,则更新该ID对应的数据,可以多个更改后提交,请问怎么实现?
...全文
286 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
feng_sundy 2004-10-28
  • 打赏
  • 举报
回复
在循环数据的时候把每条记录的数据隐藏起来
例如如
<%for i=0 to 5
id = rs.(..)..
%>
<input type="checkbox" value="<%=id%>" name="checkFlag">
<input type="hidden" value="<%=modiValue%>" name="field01<%=id%>"><br>
<%next%>

然后在后台取得
checkFlag = request.form("checkFlag")
从中取得要更改的Id,
然后组合数据字段"field01 & " & id,来取得更改的值

组合SQL,条件为ID,执行SQL。。就完成了


siyuzhang 2004-10-28
  • 打赏
  • 举报
回复
<form name = modify >
<table border="0" width="776" cellspacing="0" cellpadding="0" height="115">
<tr>
<td width="100%" bgcolor="#FCF6E5" height="1" valign="top" style="padding-left: 50; padding-top: 0">
<p align="left"><img border="0" src="image/tb1.gif" width="100" height="28"></td>
</tr>
<center>
<tr>
<td width="100%" bgcolor="#FFFFFF" height="137" valign="top" style="padding-top: 0">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="190">
<tr>
<td width="7%" bgcolor="#FDFAEE" height="37" valign="top"><img border="0" src="image/xx.htm1.gif" width="182" height="67"></td>
<td width="91%" height="190" valign="top" rowspan="2">
<div align="center">
<%
dim leibie
dim rs
dim pagecount
leibie=request.querystring("lb")
keyword=request.querystring("key")
set rs=server.createobject("adodb.recordset")
if leibie="" then
rs.open "select * from ysfw where bz='1'",conn,1,1
else
rs.open "select * from ysfw where bz='1' and district like '%"&leibie&"%' and name like '%"&keyword&"%' order by district",conn,1,1
end if
if rs.eof and rs.bof then
%>
<table border="1" width="96%" bordercolor="#000000" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#FFFFFF">
<tr>
<td width="10%" align="center" style="line-height: 150%; font-size: 9pt" bgcolor="#F8EBC2"> 公司资料列表</td>
</tr>
<tr>
<td width="10%" align="center" style="line-height: 150%; font-size: 9pt" bgcolor="#FDFAEE"> 暂时还没有需要修改的资料</td>
</tr>
</table>
<%
else
rs.pagesize=6
pagecount = rs.pagecount
page =request.querystring("page")
if (page <> "") then
if (isnumeric(page)) then
page = clng(page)
else
page = 1
end if
else
page = 1
end if
if page<1 then page=1
if page>rs.pagecount then page=rs.pagecount
rs.absolutepage=page
%>

<table border="1" width="96%" bordercolor="#000000" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#FFFFFF">
<tr>


<td width="2%" align="center" style="line-height: 150%; font-size: 10pt" bgcolor="#F8EBC2"> 选
 </td>
<td width="10%" align="center" style="line-height: 150%; font-size: 10pt" bgcolor="#F8EBC2" >区  
名</td>
<td width="20%" align="center" style="line-height: 150%; font-size: 10pt" bgcolor="#F8EBC2">名 
称</td>
<td width="20%" align="center" style="line-height: 150%; font-size: 10pt" bgcolor="#F8EBC2">服务 
内容</td>
<td width="30%" align="center" style="line-height: 150%; font-size: 10pt" bgcolor="#F8EBC2">地址</td>
<td width="18%" align="center" style="line-height: 150%; font-size: 10pt" bgcolor="#F8EBC2">电 
话</td>

</tr>
<%for i=1 to rs.pagesize%>
<tr bgcolor="#99ccff" >
<td width="2%" align="center" style="line-height: 150%; font-size: 10pt" bgcolor="#FDFAEE"><input name="seleon" type=checkbox value=<%=rs("id")%> ></td>
<td width="10%" align="center" style="line-height: 150%; font-size: 9pt" bgcolor="#FDFAEE"><input type=text id="district" name="district" value=<%=rs("district")%> ></td>
<td width="20%" align="center" style="line-height: 150%; font-size: 9pt" bgcolor="#FDFAEE"><input type=text name=nam value=<%=rs("name")%>"></a></td>
<td width="20%" align="center" style="line-height: 150%; font-size: 9pt" bgcolor="#FDFAEE"><input type=text name=content value=<%=rs("content")%>></td>
<td width="30%" align="center" style="line-height: 150%; font-size: 9pt" bgcolor="#FDFAEE"><input type=text name=address value=<%=rs("address")%>></td>
<td width="18%" align="center" style="line-height: 150%; font-size: 9pt" bgcolor="#FDFAEE"><input type=text name=phone value=<%=rs("phone")%>></td>

</tr>
<%
rs.movenext
if rs.eof then exit for
next
%>
</table>
<input type=button onclick="modi()" value="修改">  <input type=button onclick="dele()" value="删除">
</form>
我现在不知道怎么写MODI(),和dele()函数,请帮忙看看!!!
lhzongji 2004-10-28
  • 打赏
  • 举报
回复
然后在updateDatabase.asp中写好更新的SQL语句就行了。
lhzongji 2004-10-28
  • 打赏
  • 举报
回复
<SELECT size=2 id=select1 name=select1 onclick="updateDatabase(this.value,select1.options[select1.selectedIndex].outerText)" style="WIDTH: 261px; HEIGHT: 224px">
<OPTION value="1">3</OPTION>
<OPTION value="2">4</OPTION>
<OPTION value="3">5</OPTION></SELECT>


<SCRIPT LANGUAGE=javascript>
<!--
function updateDatabase(hId,hValue)
{
window.showModalDialog("updateDatabase.asp?hId=" + hId + "&hValue=" + hValue,"newwindow","dialogWidth:1px;dialogHeight:1px;dialogLeft:1px;dialogTop:1px");
}
//-->
</SCRIPT>
siyuzhang 2004-10-28
  • 打赏
  • 举报
回复
Microsoft VBScript 运行时错误 错误 '800a0009'

下标越界: 'i'

/modify.asp,行98

98行为

conn.execute "update ysfw set district='" & split(request("district" & split(request("seleon"),",")(i)),",")(i) & "',name='" & split(request("nam" & split(request("seleon"),",")(i)),",")(i) & "',content='" & split(request("content" & split(request("seleon"),",")(i)),",")(i) & "',address='" & split(request("address" & split(request("seleon"),",")(i)),",")(i) & "',phone='" & split(request("phone" & split(request("seleon"),",")(i)),",")(i) & "' where id=" & split(request("seleon"),",")(i)


原因是:for i=0 to ubound(split(request("seleon"),",")) 中的 ubound(split(request("seleon"),",")) 吧,怎么解决?
siyuzhang 2004-10-28
  • 打赏
  • 举报
回复
不好意思,我没有仔细看,谢谢!非常感谢!
iuhxq 2004-10-28
  • 打赏
  • 举报
回复
http://blog.csdn.net/iuhxq/archive/2004/09/24/115990.aspx
lhzongji 2004-10-28
  • 打赏
  • 举报
回复
修改删除都在页面最上部的代码部分

<%
if request("action")="modi" then
for i=0 to ubound(split(request("seleon"),","))
conn.execute "update ysfw set district='" & split(request("district" & split(request("seleon"),",")(i)),",")(i) & "',name='" & split(request("nam" & split(request("seleon"),",")(i)),",")(i) & "',content='" & split(request("content" & split(request("seleon"),",")(i)),",")(i) & "',address='" & split(request("address" & split(request("seleon"),",")(i)),",")(i) & "',phone='" & split(request("phone" & split(request("seleon"),",")(i)),",")(i) & "' where id=" & split(request("seleon"),",")(i)
next

Response.Write "<script language=javascript>alert('修改完毕');</script>"
end if

if request("action")="dele" then
conn.execute "delete from ysfw where id in (" & request("seleon") & ")"
Response.Write "<script language=javascript>alert('删除完毕');</script>"
end if
%>
lhzongji 2004-10-28
  • 打赏
  • 举报
回复
晕,难道我这个不是一个页面吗?

我没有用第二个页面,拜托你仔细看。
siyuzhang 2004-10-28
  • 打赏
  • 举报
回复
我就是不想用另外的页面来控制,如果这样我就没有必要写这个函数了,我是想在一个页面里面用两个函数来实现
lhzongji 2004-10-28
  • 打赏
  • 举报
回复
我假设你的这个页面为yourpage
lhzongji 2004-10-28
  • 打赏
  • 举报
回复
好了。你去调试一下吧
lhzongji 2004-10-28
  • 打赏
  • 举报
回复
<%
if request("action")="modi" then
for i=0 to ubound(split(request("seleon"),","))
conn.execute "update ysfw set district='" & split(request("district" & split(request("seleon"),",")(i)),",")(i) & "',name='" & split(request("nam" & split(request("seleon"),",")(i)),",")(i) & "',content='" & split(request("content" & split(request("seleon"),",")(i)),",")(i) & "',address='" & split(request("address" & split(request("seleon"),",")(i)),",")(i) & "',phone='" & split(request("phone" & split(request("seleon"),",")(i)),",")(i) & "' where id=" & split(request("seleon"),",")(i)
next

Response.Write "<script language=javascript>alert('修改完毕');</script>"
end if

if request("action")="dele" then
conn.execute "delete from ysfw where id in (" & request("seleon") & ")"
Response.Write "<script language=javascript>alert('删除完毕');</script>"
end if
%>
<form name = modify >
<table border="0" width="776" cellspacing="0" cellpadding="0" height="115">
<tr>
<td width="100%" bgcolor="#FCF6E5" height="1" valign="top" style="padding-left: 50; padding-top: 0">
<p align="left"><img border="0" src="image/tb1.gif" width="100" height="28"></td>
</tr>
<center>
<tr>
<td width="100%" bgcolor="#FFFFFF" height="137" valign="top" style="padding-top: 0">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="190">
<tr>
<td width="7%" bgcolor="#FDFAEE" height="37" valign="top"><img border="0" src="image/xx.htm1.gif" width="182" height="67"></td>
<td width="91%" height="190" valign="top" rowspan="2">
<div align="center">
<%
dim leibie
dim rs
dim pagecount
leibie=request.querystring("lb")
keyword=request.querystring("key")
set rs=server.createobject("adodb.recordset")
if leibie="" then
rs.open "select * from ysfw where bz='1'",conn,1,1
else
rs.open "select * from ysfw where bz='1' and district like '%"&leibie&"%' and name like '%"&keyword&"%' order by district",conn,1,1
end if
if rs.eof and rs.bof then
%>
<table border="1" width="96%" bordercolor="#000000" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#FFFFFF">
<tr>
<td width="10%" align="center" style="line-height: 150%; font-size: 9pt" bgcolor="#F8EBC2"> 公司资料列表</td>
</tr>
<tr>
<td width="10%" align="center" style="line-height: 150%; font-size: 9pt" bgcolor="#FDFAEE"> 暂时还没有需要修改的资料</td>
</tr>
</table>
<%
else
rs.pagesize=6
pagecount = rs.pagecount
page =request.querystring("page")
if (page <> "") then
if (isnumeric(page)) then
page = clng(page)
else
page = 1
end if
else
page = 1
end if
if page<1 then page=1
if page>rs.pagecount then page=rs.pagecount
rs.absolutepage=page
%>

<table border="1" width="96%" bordercolor="#000000" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#FFFFFF">
<tr>


<td width="2%" align="center" style="line-height: 150%; font-size: 10pt" bgcolor="#F8EBC2"> 选
 </td>
<td width="10%" align="center" style="line-height: 150%; font-size: 10pt" bgcolor="#F8EBC2" >区  
名</td>
<td width="20%" align="center" style="line-height: 150%; font-size: 10pt" bgcolor="#F8EBC2">名 
称</td>
<td width="20%" align="center" style="line-height: 150%; font-size: 10pt" bgcolor="#F8EBC2">服务 
内容</td>
<td width="30%" align="center" style="line-height: 150%; font-size: 10pt" bgcolor="#F8EBC2">地址</td>
<td width="18%" align="center" style="line-height: 150%; font-size: 10pt" bgcolor="#F8EBC2">电 
话</td>

</tr>
<%for i=1 to rs.pagesize%>
<tr bgcolor="#99ccff" >
<td width="2%" align="center" style="line-height: 150%; font-size: 10pt" bgcolor="#FDFAEE"><input name="seleon" type=checkbox value="<%=rs("id")%>" ></td>
<td width="10%" align="center" style="line-height: 150%; font-size: 9pt" bgcolor="#FDFAEE"><input type=text id="district<%=rs("id")%>" name="district<%=rs("id")%>" value=<%=rs("district")%> ></td>
<td width="20%" align="center" style="line-height: 150%; font-size: 9pt" bgcolor="#FDFAEE"><input type=text name="nam<%=rs("id")%>" value="<%=rs("name")%>"></a></td>
<td width="20%" align="center" style="line-height: 150%; font-size: 9pt" bgcolor="#FDFAEE"><input type=text name="content<%=rs("id")%>" value=<%=rs("content")%>></td>
<td width="30%" align="center" style="line-height: 150%; font-size: 9pt" bgcolor="#FDFAEE"><input type=text name="address<%=rs("id")%>" value=<%=rs("address")%>></td>
<td width="18%" align="center" style="line-height: 150%; font-size: 9pt" bgcolor="#FDFAEE"><input type=text name="phone<%=rs("id")%>" value=<%=rs("phone")%>></td>

</tr>
<%
rs.movenext
if rs.eof then exit for
next
%>
</table>
<input type=button onclick="modi()" value="修改">  <input type=button onclick="dele()" value="删除">
<input type="hidden" name="lb" value="<%=request("lb")%>">
<input type="hidden" name="key" value="<%=request("key")%>">
</form>
<SCRIPT LANGUAGE=javascript>
<!--
function modi()
{
document.modify.method="POST";
document.modify.action="yourpage.asp?action=modi";
document.modify.submit();
}

function dele()
{
document.modify.method="POST";
document.modify.action="yourpage.asp?action=dele";
document.modify.submit();
}
//-->
</SCRIPT>

87,922

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧