Solved

Updating multiple records with ASP

Posted on 2011-02-27
6
243 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
Comment Utility
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
Comment Utility
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
Comment Utility
Here, I made a demo to show you how it goes now... Document1.htm

Try it and see.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Closing Comment

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

Expert Comment

by:rhawk
Comment Utility
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
Comment Utility
Thank you so much, everything is working now. I really appreciate your help.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now