Solved

Updating multiple records with ASP

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

Try it and see.
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

691 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