Solved

Updating multiple records with ASP

Posted on 2011-02-27
6
249 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
  • 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 500 total points
ID: 34992885
Here, I made a demo to show you how it goes now... Document1.htm

Try it and see.
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

791 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