Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Updating multiple records with ASP

Posted on 2011-02-27
6
Medium Priority
?
257 Views
Last Modified: 2012-05-11
I'm trying to update all returned records at the same time, where the checkbox is checked.
Something is missing from my code; would you please let me know how I could update the AutoStatus field of each selected record?
<%
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="editor" method="post" action="Approval_send.asp">

<table border="1">
<tr>
<th>Employee Name</th>
<th>Emp.#</th>
<th>Auto Status</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("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>

Open in new window

0
Comment
Question by:baxtalo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 2

Expert Comment

by:rhawk
ID: 34992816
Hi baxtalo,
Not sure on this, just looking quickly over your code but it looks like you are trying to update the values in the Javascrip client-side? You cnanot do that.

I would make this change...
do until rs.EOF
%>
<tr>
<td><%=rs("EmpName")%></td>
<td><%=rs("Emp_Id")%></td>
<td><%=rs("AutoStatus")%></td>
<td><input type="checkbox" name="ID_<%=rs("ID").Value%>" value="1"></td>
</tr>
<%
rs.MoveNext


Then in the receiving page set all checkflags to false. Then run through each request field name received and it begins with "ID_" then you get the ID number from the name by using RIGHT('<fieldname>',LEN(<fieldname>)-3) and set the value to true (I am assuming the database has the field as a true/false value.

Do you follow that? If not let me know and I can toss together a fast version of the 2 pages to show you.

David
0
 
LVL 2

Expert Comment

by:rhawk
ID: 34992875
DOH! I see what you are doing. You want to change them IN the HTML based on the top one.
Make this function in the Javascript:
function checkLikeMe($) {
    var x = document.getElementsByName('ID');
    for (var y = 0; y < x.length; y++)
        x[y].checked = $;
}

Now change the top input checkbox to:
<input type="checkbox" onClick="checkLikeMe(this.checked)">

That ought to do it for you.
0
 
LVL 2

Accepted Solution

by:
rhawk earned 2000 total points
ID: 34992885
Here, I made a demo to show you how it goes now... Document1.htm

Try it and see.
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

Author Closing Comment

by:baxtalo
ID: 34992923
Thank you very much, it's going to work now. Have a great day!
0
 
LVL 2

Expert Comment

by:rhawk
ID: 34992948
One question... How are you going to know what record to update on the receiving end? I think you may not have that one yet. Do you need more code to do that as well?
0
 

Author Comment

by:baxtalo
ID: 34994557
Thank you so much, everything is working now. I really appreciate your help.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question