<script language="javascript">
function CheckAll(form)
{ ///定義函數checkall,參數為form
for (var i=0;i<form.elements.length;i++)
///循環,form.elements.length得到表單裡的控件個數
{
///把表單裡的內容依依付給e這個變量
var e = form.elements[i];
if (e.name != ’chkall’)
e.checked = form.chkall.checked;
}
}
</script>
<form id="form1" name="form1" method="post" action="">
<table width="200" cellspacing="1" cellpadding="0">
<tr>
<td width="26">全選</td>
<td width="169"><input name="chkall" type="checkbox" id="chkall" value="all" onclick="CheckAll(this.form)" /></td>
</tr>
<tr>
<td><input name="id" type="checkbox" id="id" value="1" /></td>
<td>1 標題1</td>
</tr>
<tr>
<td><input name="id" type="checkbox" id="id" value="2" /></td>
<td>2 標題2</td>
</tr>
<tr>
<td><input name="id" type="checkbox" id="id" value="3" /></td>
<td> 3 標題3</td>
</tr>
<tr>
<td><input name="id" type="checkbox" id="id" value="4" /></td>
<td>4 標題4</td>
</tr>
<tr>
<td><input name="id" type="checkbox" id="id" value="5" /></td>
<td>5 標題5</td>
</tr>
<tr>
<td><input name="id" type="checkbox" id="id" value="6" /></td>
<td>6 標題6</td>
</tr>
<tr>
<td><input name="id" type="checkbox" id="id" value="7" /></td>
<td>7 標題7</td>
</tr>
<tr>
<td><input name="id" type="checkbox" id="id" value="8" /></td>
<td>8 標題8</td>
</tr>
<tr>
<td><input name="id" type="checkbox" id="id" value="9" /></td>
<td>9 標題9</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="刪除" /></td>
</tr>
</table>
</form>
如需傳值到另一文件
delete.asp文件:
<!--#include file="inc/conn.asp"-->
<%
Num=request.form("checkbox1").count
if Num=0 then
Response.Write ("請選擇要刪除的新聞")
Response.End
end if
ids=request.Form("checkbox1")
sqlStr="Delete * From indexad Where id in ("&ids&")"
conn.execute(sqlStr)
Response.redirect(request.servervariables("http_referer"))
Response.End
%>
方法2
<%
Num=request.form("DelID").count
if Num=0 then
Response.Write ("請選擇要刪除的新聞")
Response.End
end if
for i=1 to Num
set rs=Server.CreateObject("adodb.Recordset")
sql="Select * from News where NewsID="&request.form("DelID")(i)
rs.open sql,conn,1,1
if not rs.eof then
conn.execute("Delete From News Where NewsID="&request.form("DelID")(i))
conn.execute("Delete From Review Where NewsID="&request.form("DelID")(i))
else
Response.Write ("新聞刪除失敗")
Response.End
end if
rs.close
set rs=nothing
next
Response.Write ("成功將選定新聞刪除")
Response.End
%>