How to select multiple checkboxes

I would like to select/deselect all checkboxes by clicking the checkbox in the table header.
When all checkboxes are selected I would like to submit my form to be processed by my Delete.asp
Would you please help me write the code? I'd really appreciate your help, thank you.
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/DB/Autos.mdb"))

set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT * FROM Auto_Table", conn
%>

<html>
<head>
<title>All Requests</title>
</head>
<body>

<table border="1">
<tr>
<th>Employee Name</th>
<th>Emp.#</th>
<th>Phone Number</th>
<th>Date</th>
<th><input type="checkbox"></th>
</tr>
<%
if not (rs.EOF or rs.BOF) then rs.movefirst
do until rs.EOF
%>
<tr>
<td><%=rs("EmpName")%></td>
<td><%=rs("Emp_Id")%></td>
<td><%=rs("PhoneNo")%></td>
<td><%=rs("adj_svc_dt")%></td>
<td><input type="checkbox" name="Process"></td>
</tr>
<%
rs.MoveNext
loop
rs.Close
conn.Close
%>
</table>

</body>
</html>

Open in new window

baxtaloAsked:
Who is Participating?
 
rg20Connect With a Mentor Commented:
try
StrSQL = "Update Auto_Table SET AutoStatus= '" & myAutoStatus & "', Pipa= '" & myPipa & "', ApprovedBy= '" & myApprovedBy & "' Where ID in ("&myId&"}"

0
 
baxtaloAuthor Commented:
I managed to select all checkboxes by clicking the checkbox in the TH.
I just don't know how I can delete all selected records at the same time.
Would you please have a look at the code below. What do I need to add so that my Delete.asp can process the query?
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/EWR/DB/Autos.mdb"))

set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT * FROM EWRAuto_Table", conn
%>

<html>
<head>
<title>All Requests</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
}
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
}
}
// End -->
</script>

</head>
<body>

<form name=myform action="Delete.asp" method=post>

<table border="1">
<tr>
<th>Employee Name</th>
<th>Emp.#</th>
<th>Phone Number</th>
<th>Date</th>
<th><input type="checkbox" onClick="this.value=check(this.form.ID)"></th>
</tr>
<%
if not (rs.EOF or rs.BOF) then rs.movefirst
do until rs.EOF
%>
<tr>
<td><%=rs("EmpName")%></td>
<td><%=rs("Emp_Id")%></td>
<td><%=rs("PhoneNo")%></td>
<td><%=rs("adj_svc_dt")%></td>
<td><input type="checkbox" name="ID" value="<%=rs("ID") %>"></td>
</tr>
<%
rs.MoveNext
loop
rs.Close
conn.Close
%>
</table>

<input type="Submit" name="Submit" value="Submit" />

</form>


</body>
</html>

Open in new window

0
 
ProculopsisCommented:

Are you after something like this.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
baxtaloAuthor Commented:
I would like to process all records at the same time. I'm getting now closer, but the version below deletes only one record upon Submit. I would like all checked records deleted at the same time. Please take a look:
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/DB/Autos.mdb"))

set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT * FROM Auto_Table", conn
%>

<html>
<head>
<title>All Requests</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
}
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
}
}
// End -->
</script>

</head>
<body>

<form name=myform action="Delete.asp?ID=<% = rs("ID") %>" method=post>

<table border="1">
<tr>
<th>Employee Name</th>
<th>Emp.#</th>
<th>Phone Number</th>
<th>Date</th>
<th><input type="checkbox" onClick="this.value=check(this.form.ID)"></th>
</tr>
<%
if not (rs.EOF or rs.BOF) then rs.movefirst
do until rs.EOF
%>
<tr>
<td><%=rs("EmpName")%></td>
<td><%=rs("Emp_Id")%></td>
<td><%=rs("PhoneNo")%></td>
<td><%=rs("adj_svc_dt")%></td>
<td><input type="checkbox" name="ID" value="<%=rs("ID") %>"></td>
</tr>
<%
rs.MoveNext
loop
rs.Close
conn.Close
%>
</table>

<input type="Submit" name="Submit" value="Submit" />

</form>

</body>
</html>

Open in new window

0
 
rg20Commented:
To delete multiple records, you will need to know which checkboxes are to which records.

What I do is give the checkbox a name like this
checkbox name="ckbx_"&ID

After the user checkes everything, you just cycle through the request form checkboxes for the name starting with ckbx_.
Then parse the name and you know what record to delete.

0
 
baxtaloAuthor Commented:
I'm struggling with this since this morning. I would rather like to update the checked records.
The following fields need to be updated: AutoStatus, Pipa, ApprovedBy
When I submit I get the following error:

Microsoft JET Database Engine error '80040e14'
Syntax error (comma) in query expression 'ID=3, 4, 5, 6, 7, 8, 9, 10, 11'.

Please have a look at my pages (All_.asp and Process.asp); would you know why it won't update my fields?
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/EWR/DB/Autos.mdb"))

set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT * FROM EWRAuto_Table", conn
%>

<html>
<head>
<title>All Requests</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function checkLikeMe($) {
    var x = document.getElementsByName('ID');
    for (var y = 0; y < x.length; y++)
        x[y].checked = $;
}

// End -->
</script>

</head>
<body>

<form name="editor" method="post" action="Process.asp">

<table border="1">
<tr>
<th>Employee Name</th>
<th>Emp.#</th>
<th>Auto Status</th>
<th><input type="checkbox" onClick="checkLikeMe(this.checked)"></th>
</tr>
<%
if not (rs.EOF or rs.BOF) then rs.movefirst
do until rs.EOF
%>
<tr>
<td><%=rs("EmpName")%></td>
<td><%=rs("Emp_Id")%></td>
<td><%=rs("AutoStatus")%></td>
<td><input type="checkbox" name="ID" value="<%=rs("ID") %>"></td>
</tr>
<%
rs.MoveNext
loop
rs.Close
conn.Close
%>
</table>


<br /><br />
<select name="AutoStatus">
<option value="Pending">Select Status</option>
<option value="Disapproved">Disapproved</option>
<option value="Approved">Approved</option>
</select>

<input type="hidden" name="Pipa" value="&#252">
<input name="ApprovedBy" type="hidden" id="ApprovedBy" value="<%=Request.ServerVariables("LOGON_USER")%>" />
<input type="Submit" name="Submit" value="Update" />
</center>
</form>

</body>
</html>


AND THIS IS the Process.asp:

<%
Set objConn = CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath ("/DB/Autos.mdb") & ";"
objConn.Open

myId = Request.form("ID")

myAutoStatus = request.Form("AutoStatus")
myPipa = request.Form("Pipa")
myApprovedBy = request.Form("ApprovedBy")


StrSQL = "Update Auto_Table SET AutoStatus= '" & myAutoStatus & "', Pipa= '" & myPipa & "', ApprovedBy= '" & myApprovedBy & "' Where ID="&myId&""
objConn.Execute StrSQL

'Redirect to the UPDATED page
Response.Redirect "All_.asp"
%>

Open in new window

0
 
baxtaloAuthor Commented:
I tried and now I get this error message:

Microsoft JET Database Engine error '80040e14'
Syntax error in query expression 'ID in (3, 4, 5, 6, 7, 8, 9, 10, 11}'.
0
 
rg20Commented:
If your ID's are strings, then you need to do a replace

Where ID in ("&replace(myId,",", """,""" &"}"
 before executing your SQL, can you do a response.write to see the entire query?
0
 
baxtaloAuthor Commented:
Where do I have to put the response.write? When I used Where ID in ("&replace(myId,",", """,""" &"}"
I got this error:
Microsoft VBScript compilation error '800a03ee'

Expected ')'

/EWR/Autos/Process.asp, line 14

StrSQL = "Update Auto_Table SET AutoStatus= '" & myAutoStatus & "', Pipa= '" & myPipa & "', ApprovedBy= '" & myApprovedBy & "' Where ID in ("&replace(myId,",", """,""" &"}"

0
 
rg20Commented:
I forgot a closing bracket for the replace

StrSQL = "Update Auto_Table SET AutoStatus= '" & myAutoStatus & "', Pipa= '" & myPipa & "', ApprovedBy= '" & myApprovedBy & "' Where ID in ("&replace(myId,",", """,""") &"}"

0
 
baxtaloAuthor Commented:
Thank you very much, your solution is perfect. I just made a spelling mistake; that's why it didn't work when I tried it for the first time. Now it's working, thanks again...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.