Replies Back to Article
Delete Multiple Records Using Checkboxes...
Yes it can be done in Javascript
When setting up this system, I am greeted with a problem, I am seeing that the system cannot find the rows to be deleted. I am using several recordsets in order to show messages (am using a home built messaging system). Whatever is done, it cannot find the messageID it needs to delete.
Any ideas what can be the problem?
Ok, I'm making some progress. I went to the referenced page named "Multiple delete using Javascript " at http://dmxzone.com/ShowDetail.asp?NewsId=3430, and I thought I could somehow change it to an Insert to do what I need...a page that inserts multiple records from one form into one table. My plan is to get the Delete Behavior to work first using the script from that page, then I was going to change it to an Insert page.
But I'm getting an error message (see below). I've also included the page's code, and the query that's generated upon submittal. If someone can help me out with this, or point me in the right direction, it would be greatly appreciated. If anyone knows of a working script or extension (no demos) that I can get a hold of that will do a multiple insert from one form into one DB table, please let me know. Thanks in advance.
KWilliams
I'm getting this error message:
>Microsoft OLE DB Provider for SQL Server error '80040e14'
>Line 1: Incorrect syntax near '(03-005 )'.
>/Employment/app_jobs3C.asp, line 28
This is the query that's generated upon submittal of the form:
>http://www.douglas-county.com/Employment/app_jobs3C.asp?checkbox=03-005++++&Submit=Add+Job%28s%29[/Q]
And finally, this is the page's code using the JavaScript from DMXZone's page referenced above:
<%@LANGUAGE="JAVASCRIPT"%>
<!--#include file="Connections/strConn.asp" -->
<%
if(String(Request.Querystring("checkbox")) != "undefined"){ Command1__varJob_ID = String(Request.Querystring("checkbox"));}
%>
<%
// Script enabling multiple delete of records
// If there is no choice, the page "app_jobsconf.asp" is loaded again
// and a message box alerts the user
var emptystring="String"(Request.Querystring("checkbox")) // The var "emptystring" is used to check the "choice or no choice"
if (emptystring !="undefined") { // If the var "emptystring" contains the user's choice, the datas are deleted
var parenthesisin="("; //var containing the string "("
var parenthesisout=")"; //var containing the string ")"
//Var "parenthesisin" and "parenthesisout" are added before and after the var "String(Request.Querystring("checkbox"))"
if (String(Request.Querystring("checkbox")) != "undefined"){ Command1__varJob_ID =parenthesisin + String(Request.Querystring("checkbox"))+ parenthesisout;}
var Command1 = Server.CreateObject("ADODB.Command");
Command1.ActiveConnection = MM_strConn_STRING;
// Create a command in "Data Bindings", type="DELETE", SQL="DELETE * FROM Employ_Jobs WHERE Job_ID IN Command1__varJob_ID"
// varJob_ID is a var which value is "Request.Querystring("checkbox")"
var Command1 = Server.CreateObject("ADODB.Command");
Command1.ActiveConnection = MM_strConn_STRING;
Command1.CommandText = "DELETE FROM dbo.Employ_Jobs WHERE Job_ID IN '"+ Command1__varJob_ID.replace(/'/g, "''") + "'";
Command1.CommandType = 1;
Command1.CommandTimeout = 0;
Command1.Prepared = true;
Command1.Execute();
Response.Redirect("app_jobsconf.asp")
}
else {%>
<%
var rs_App1A__MMColParam = "Seqno";
if(String(Request.QueryString("id")) != "undefined") {
rs_App1A__MMColParam = String(Request.QueryString("id"));
}
%>
<%
var rs_App1A__varApp_ID = "%";
if(String(Session("App_ID")) != "undefined") {
rs_App1A__varApp_ID = String(Session("App_ID"));
}
%>
<%
var rs_App1A__varPassword = "%";
if(String(Session("Password")) != "undefined") {
rs_App1A__varPassword = String(Session("Password"));
}
%>
<%
var rs_App1A = Server.CreateObject("ADODB.Recordset");
rs_App1A.ActiveConnection = MM_strConn_STRING;
rs_App1A.Source = "SELECT * FROM dbo.Employment_App WHERE App_ID LIKE '"+ rs_App1A__varApp_ID.replace(/'/g, "''") + "' AND Password LIKE '"+ rs_App1A__varPassword.replace(/'/g, "''") + "' AND Seqno = "+ rs_App1A__MMColParam.replace(/'/g, "''") + ""; rs_App1A.CursorType = 0; rs_App1A.CursorLocation = 2; rs_App1A.LockType = 3; rs_App1A.Open(); var rs_App1A_numRows = 0; %>
<% var rs_App1B = Server.CreateObject("ADODB.Recordset");
rs_App1B.ActiveConnection = MM_strConn_STRING;
rs_App1B.Source = "SELECT * FROM Jobs WHERE Job_ID IN (SELECT Job_ID FROM Employ_Jobs) ORDER BY Job_Title ASC"; rs_App1B.CursorType = 0; rs_App1B.CursorLocation = 2; rs_App1B.LockType = 3; rs_App1B.Open(); var rs_App1B_numRows = 0; %>
<%
var Repeat1__numRows = -1;
var Repeat1__index = 0;
rs_App1B_numRows += Repeat1__numRows;
%>
<% if (rs_App1A.EOF) Response.Redirect("http://www.douglas-county.com/Employment/noaccess.asp")%>
<%
Session("Seqno") = rs_App1A.Fields.Item("Seqno").Value
Session("App_ID") = rs_App1A.Fields.Item("App_ID").Value
Session("Password") = rs_App1A.Fields.Item("Password").Value
%>
<% var MM_paramName = ""; %>
<%
// *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters
// create the list of parameters which should not be maintained
var MM_removeList = "&index="; if (MM_paramName != "") MM_removeList += "&" +
MM_paramName.toLowerCase() + "=";
var MM_keepURL="",MM_keepForm="",MM_keepBoth="",MM_keepNone="";
// add the URL parameters to the MM_keepURL string
for (var items="new" Enumerator(Request.QueryString); !items.atEnd();
items.moveNext()) {
var nextItem = "&" + items.item().toLowerCase() + "=";
if (MM_removeList.indexOf(nextItem) == -1) {
MM_keepURL += "&" + items.item() + "=" + Server.URLencode(Request.QueryString(items.item()));
}
}
// add the Form variables to the MM_keepForm string
for (var items="new" Enumerator(Request.Form); !items.atEnd();
items.moveNext()) {
var nextItem = "&" + items.item().toLowerCase() + "=";
if (MM_removeList.indexOf(nextItem) == -1) {
MM_keepForm += "&" + items.item() + "=" + Server.URLencode(Request.Form(items.item()));
}
}
// create the Form + URL string and remove the intial '&' from each of the strings MM_keepBoth = MM_keepURL + MM_keepForm; if (MM_keepBoth.length > 0) MM_keepBoth = MM_keepBoth.substring(1); if (MM_keepURL.length > 0) MM_keepURL = MM_keepURL.substring(1); if (MM_keepForm.length > 0) MM_keepForm = MM_keepForm.substring(1); %>
<html>
<head>
<title>Douglas County, Kansas - Online Employment Application-Step 1</title>
<meta http-equiv="Content-Type" content="text/html; charset="iso"-8859-1">
<META NAME="keywords" CONTENT="Douglas County,Douglas County KS,Douglas County Kansas,Douglas,County,Kansas,Government,KS Government,Kansas Government,Stephen A. Douglas,Quantrill,Quantrill's Raid,Lawrence,Lecompton,Baldwin,Baldwin
City,Eudora,Clinton,Jayhawks;KU,Kansas University,University of Kansas,University of KS,Baker University,Haskell,Haskell Indian Nations University,John Baldwin,Amos A. Lawrence,Samuel D. Lecompte,Kanzas Nation.">
<META NAME="description" CONTENT= "Official site for Douglas County, Kansas - Our mission is to provide for the safety and well being of the citizens of Douglas County through the professional and efficient delivery of essential public services in response to the needs of Douglas County citizens.">
<style type="text/css">
<!--
.roll { font-family:"Arial, Helvetica, sans-serif" size="1"; font-style:normal; font-weight:normal; letter-spacing:normal; text-decoration:underline; color:330066; }
A.roll:hover { size="1"; color:red; text-decoration:none;}
-->
INPUT, TEXTAREA {
font-family: "Arial, Helvetica, sans-serif";
padding: 1px;
font-size: 12px;
color: #000000;
background-color: #FFFFFF;
border: inset 2px #660000;
}
</style>
<script language="JavaScript">
<!--
<!-- Begin
if (window != top) top.location.href = location.href;
function NewWindow(mypage, myname, w, h, scroll)
{
var winl = (screen.width - w) / 1.5;
var wint = (screen.height - h) / 1.65;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll
+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode;
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}
// End -->
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1">
<table width="660" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFCC">
<tr>
<td valign="top" height="2">
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td colspan="2" bgcolor="#660000"><font size="2" face="Arial, Helvetica, sans-serif" color="#FFFFFF"><b>Position(s) applying for:</b></font></td>
</tr>
<tr bgcolor="#FFFFCC" valign="top">
<td colspan="2" height="37">
<div align="left">
<% while ((Repeat1__numRows-- != 0) && (!rs_App1B.EOF)) { %>
<input type="checkbox" name="checkbox" value="<%=(rs_App1B.Fields.Item("Job_ID").Value)%>">
<font size="2" face="Arial, Helvetica, sans-serif"><%=(rs_App1B.Fields.Item("Job_Title").Value)%><font size="1"><a class="roll" href="app_jobdesc.asp?<%=("Job_ID=" + rs_App1B.Fields.Item("Job_ID").Value)%>">View Details</a></font></font><br>
<%
Repeat1__index++;
rs_App1B.MoveNext();
}
%>
</div>
</td>
</tr>
<tr bgcolor="#FFFFCC">
<td colspan="2">
<p><font size="1" face="Arial, Helvetica, sans-serif" color="#FF0000"><b><img src="Images/bullet2.gif" width="8" height="8">To view details for each position, visit the'View Details' links above.
</b></font>
</p>
</td>
</tr>
<tr>
<td bgcolor="#FFFFCC" valign="bottom" height="2" width="66%"><font size="2" face="Arial, Helvetica, sans-serif">If you have any questions about this form, please contact the Douglas County <a class="roll" href=" webmaster <mailto:webmaster@douglas-county.com>
.mailto:webmaster@douglas-county.com">webmaster</a>.</font></td>
<td bgcolor="#FFFFCC" valign="top" height="2" width="34%" colspan="-1">
<div align="right">
<input type="button" name="Submit2" value="Cancel" onClick="window.close()">
<input type="submit" name="Submit" value="Add Job(s)">
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<%
rs_App1A.Close();
%>
<%
rs_App1B.Close();
%>
<%
}%>
I followed this tutorial nearly exactly, figuring I could use it to update a single table with two values -- one from a recordset that identifies a user, and one from the checkboxes that identify products. Each value goes into an Associations table that holds a value for the userID, and a value for a product.
I'm getting [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '='.
I think this is what's causing the trouble:
<%
strIDs = Replace(Request.Form, "&del=", ",")
strIDs = Replace(strIDs, "del=", "")
set DoAdd = Server.CreateObject("ADODB.Command")
DoAdd.ActiveConnection = MM_db_STRING
DoAdd.CommandText = "INSERT INTO dbo.MyAssociations (ProductID, MyID)" & _
" SELECT " & strIDs & "," & (rsMyID.Fields.Item("MyID").Value)
DoAdd.CommandType = 1
DoAdd.CommandTimeout = 0
DoAdd.Prepared = true
DoAdd.Execute()
Response.Redirect("login_welcome.asp")
%>
Any ideas? I'd be so grateful for help.
Although I could make it work only through the alternative way (SQL command), it was very simple!
Thanks a bunch! I love you!
i need the same function that when Check Box is Selected then on Submitting the form the Seleced Chcek Box Insert in to Another tabel of the database
need help any one having

do this on what is currently the dodelete page...
Open recordset as per selected item(s)
iterate through them and fire a insert command for each record inserting the new,copied, record into whatever table you want.
Or look at ADO functionality to do similar depending on what your performance requirements are.
Theres many ways to achieve your needs
Cheers
i followed ue steps but for updating records but i'm getting error
this is what i did
While ((Repeat1__numRows <> 0) AND (NOT rsAnswer2.EOF))
%>
<tr valign="baseline">
<td nowrap align="right"></td>
<td valign="top">
<input type="checkbox" name="answers1" value="<%=(rsAnswer2.Fields.Item("answer_no").Value)%>" >
<option value="<%=(rsAnswer2.Fields.Item("answer_no").Value)%>"><%=(rsAnswer2.Fields.Item("answers").Value)%></option> </td>
<td valign="top"><%=(rsAnswer2.Fields.Item("counts").Value)%></td>
</tr>
<%
repeat1__index="Repeat1__index+1"
repeat1__numrows="Repeat1__numRows-1"
rsAnswer2.MoveNext()
Wend
%>
</table>
<p>Othes, Please specify </p>
<p align="center">
<input type="submit" value="Next">
</p>
</form>
update page
<%
strIDs = Replace(Request.querystring, "&answer1=", ",")
strIDs = Replace(strIDs, "answer1=", "")
set cmdUpdateAns = Server.CreateObject("ADODB.Command")
cmdUpdateAns.ActiveConnection = MM_srcsurvey_conn_STRING
cmdUpdateAns.CommandText = "UPDATE answers SET counts = counts + 1 where answer_no IN (" & strIDs & ")"
cmdUpdateAns.CommandType = 1
cmdUpdateAns.CommandTimeout = 0
cmdUpdateAns.Prepared = true
cmdUpdateAns.Execute()
%>
please help
here's my code,
strIDs = Replace(Request.Form, "&del=", ",")
strIDs = Replace(strIDs, "del=", "")
set DoDelete = Server.CreateObject("ADODB.Command")
DoDelete.ActiveConnection = MM_PreApply_STRING
DoDelete.CommandText = "DELETE FROM dbo.preapplication WHERE SecondaryID IN (" & strIDs & ")"
DoDelete.CommandType = 1
DoDelete.CommandTimeout = 0
DoDelete.Prepared = true
DoDelete.Execute()
Response.Redirect("cleaner.asp")
%>
SecondaryID is the name of my ID field.
Not sure what it is but I keep getting "Incorrect syntax near '='. " when I try and submit my delete request.
I know it must be a simple fix but I just dont see it. What am I missing?
hi. i am doing about delete record
this is my coding for deleteKom.asp
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../Connections/data1.asp" -->
<%
Dim RSKom
Dim RSKom_numRows
Set RSKom = Server.CreateObject("ADODB.Recordset")
RSKom.ActiveConnection = MM_data1_STRING
RSKom.Source = "SELECT * FROM tblKom"
RSKom.CursorType = 0
RSKom.CursorLocation = 2
RSKom.LockType = 3
RSKom.Open()
RSKom_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
RSKom_numRows = RSKom_numRows + Repeat1__numRows
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset="iso-8859-1"" />
<title>SAPURA::Portal ACV 300 Simulator</title>
<style type="text/css">
<!--
.style1 {font-weight: bold}
-->
</style>
</head>
<body>
<form name="f" method="post" action="dodelete.asp">
<table width="1193" height="789" border="0" background="images/adnan_4.jpg">
<tr>
<td width="185" height="134"><img src="images/logo sapura.gif" alt="logo sapura" width="183" height="72" /></td>
<td width="843"><div align="center"><img src="images/banner.jpg" alt="banner" width="830" height="87" /></div></td>
<td width="143"><div align="center"><img src="images/defence.jpg" alt="defence" width="131" height="91" /></div></td>
</tr>
<tr>
<td height="246"><script type="text/javascript">
var d = new Date()
document.write("Date:")
document.write(d.getDate())
document.write(".")
document.write(d.getMonth() + 1)
document.write(".")
document.writeln(d.getFullYear())
document.write("<br>")
</script>
<p class="style1"><script src="http://www.clocklink.com/embed.js"></script><script type="text/javascript" language="JavaScript">obj=new Object;obj.clockfile="otsukashokai001-navy.swf";obj.TimeZone="Malaysia_KualaLumpur";obj.width=100;obj.height=100;obj.wmode="transparent";showClock(obj);</script>
</td>
<td><div align="center">
<table width="708" height="62" border="1" align="center">
<tr bgcolor="#66FFCC">
<td width="60"> </td>
<td width="166"><div align="center"><strong>Fullname</strong></div></td>
<td width="220"><div align="center"><strong>Email</strong></div></td>
<td width="234"><div align="center"><strong>Comment</strong></div></td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT RSKom.EOF))
%>
<tr>
<td><div align="center">
<input type="checkbox" name="del" value="<%=(RSKom.Fields.Item("ID").Value)%>">
</div></td>
<td><%=(RSKom.Fields.Item("Fullname").Value)%></td>
<td><%=(RSKom.Fields.Item("Email").Value)%></td>
<td><%=(RSKom.Fields.Item("Comment").Value)%></td>
</tr>
<%
repeat1__index="Repeat1__index+1"
repeat1__numrows="Repeat1__numRows-1"
RSKom.MoveNext()
Wend
%>
</table>
<p align="center">
<input type="submit" value="Delete" />
</p>
<p align="center"> </p></td>
<td> </td>
</tr>
<tr>
<td height="199"><table width="106" border="0" align="center">
<tr>
<td width="109"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="145" height="30">
<param name="movie" value="bHomeAdmn.swf" />
<param name="quality" value="high" />
<embed src="bHomeAdmn.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="105" height="23" ></embed>
</object></td>
</tr>
<tr>
<td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="145" height="30" align="middle" title="bComment">
<param name="BGCOLOR" value="" />
<param name="movie" value="bViewCommAdmn.swf" />
<param name="quality" value="high" />
<embed src="bViewCommAdmn.swf" width="128" height="29" align="middle" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" ></embed>
</object></td>
</tr>
<tr>
<td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="145" height="30">
<param name="BGCOLOR" value="" />
<param name="movie" value="blogoutAdmn.swf" />
<param name="quality" value="high" />
<embed src="blogoutAdmn.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="105" height="23" ></embed>
</object>
<script language="JavaScript">
javascript:window.history.forward(1);
</script></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
</table></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="200"> </td>
<td><a href="http://www.google.com/">Google</a> <br />
<input name="q" framewidth="4" size="20" />
<br />
<input name="submit" type="submit" value="search" />
<input name="clear" type="reset" value="clear" /> </td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
<%
RSKom.Close()
Set RSKom = Nothing
%>
When i preview at the browser, there was nothing wrong. Then when i preview my coding on deleteaction.asp, this is my error
Error Type:
ADODB.Recordset (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/Sim/deleteaction.asp, line 30
my coding for deleteaction.asp is
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../Connections/data1.asp" -->
<%
Dim RSKom
Dim RSKom_numRows
Set RSKom = Server.CreateObject("ADODB.Recordset")
RSKom.ActiveConnection = MM_data1_STRING
RSKom.Source = "SELECT * FROM tblKom"
RSKom.CursorType = 0
RSKom.CursorLocation = 2
RSKom.LockType = 3
RSKom.Open()
RSKom_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
RSKom_numRows = RSKom_numRows + Repeat1__numRows
%>
<%
strIDs = Replace(Request.Form, "&del=", ",")
strIDs = Replace(strIDs, "del=", "")
arrIDs = Split(strIDs, ",")
%>
<%
For intCount = 0 To UBound(arrIDs)
RSKom.Filter = "ID = " & arrIDs(intCount) /Sim/deleteaction.asp, line 30
RSKom.Delete
Next
RSKom.Close()
Response.Redirect("deleteKom.asp")
%>
<%
RSKom.Close()
Set RSKom = Nothing
%>
thank you