473,387 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Classic ASP question

I have very little experience of Classic ASP, but I need to take some
data from a table, write it to the screen in a tabular format, show a
check box at the end of every row, and write some code to enable the
user to check all check boxes, and then some code to respond to a button
click to find out which rows were checked.

I know how to read data from a recordset and put it into a <table>
object, but the rest, particularly the check box bits, are giving me
problems. Can somebody please help me out?


*** Sent via Developersdex http://www.developersdex.com ***
Aug 6 '08 #1
5 4462
"Mike P" wrote:
I have very little experience of Classic ASP, but I need to take some
data from a table, write it to the screen in a tabular format, show a
check box at the end of every row, and write some code to enable the
user to check all check boxes, and then some code to respond to a button
click to find out which rows were checked.
Well, the "check all check boxes" will be JavaScript code, in the browser,
nothing to do with ASP.

And you don't say *WHAT* the code that "respond[s] to a button click" is
supposed to do. Just say "You checked boxes 17, 33, and 42"??? Or delete
records from the DB? Or copy records?

In other words, does the response need to be JS in the browser or ASP code
on the server?

*ASSUMING* you mean that you want to (say) delete all the checked records,
it's pretty easy.

Since you give us so little info about your app, I'll make some simplistic
assumptions. I'm doing it all on one page. So the <formsubmits back to
the same page and, if there are an records to be deleted, they are deleted.
Whether a delete occurred or not, all the non-deleted records are shown with
checkboxes.

<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "...your connection string..."

If Trim( Request("DELETE") ) <"" Then
' submit was pushed, delete all checked records
SQL = "DELETE FROM people WHERE id IN (" & Request("ZAP") & ")"
howMany = -1
conn.Execute SQL, howMany
Response.Write "<h2>Deleted " & howMany & " records</h2><P>"
End If
%>
<form method="POST">
<table border=1 cellpadding=5>
<%
SQL = "SELECT ID, Name, Address FROM people"
Set RS = yourAlreadyOpenConnection.Execute( SQL )
Do Until RS.EOF
%>
<tr>
<td><%=RS("Name")%></td>
<td><%=RS("Address")%></td>
<td><input type=checkbox name="ZAP" value="<%=RS("ID"%>"></td>
</tr>
<%
RS.MoveNext
Loop
%>
</table>
<input type=submit value="Delete checked people" name="DELETE">
</form>

And that's all there is to it. Presto.

p.s.: Assumes the the ID field is a numeric field. Minor change needed if
it's a text field.

Aug 6 '08 #2
Oh, what the heck...

Here's the code for adding a "CHECK ALL" button:

<HTML>
<HEAD>
<SCRIPT>
function checkAll( cbs )
{
if ( cbs.length == null )
{
// if only one checkbox
cbs.checked = true;
return; // only one to do
}
for ( var c = 0; c < cbs.length; ++c )
{
cbs[c].checked = true;
}
}
</SCRIPT>
</HEAD>
<BODY>
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "...your connection string..."

If Trim( Request("DELETE") ) <"" Then
' submit was pushed, delete all checked records
SQL = "DELETE FROM people WHERE id IN (" & Request("ZAP") & ")"
howMany = -1
conn.Execute SQL, howMany
Response.Write "<h2>Deleted " & howMany & " records</h2><P>"
End If
%>
<form method="POST">
<INPUT Type=Button Value="Check all" onClick="checkAll(this.form.ZAP);">
<table border=1 cellpadding=5>
<%
SQL = "SELECT ID, Name, Address FROM people"
Set RS = yourAlreadyOpenConnection.Execute( SQL )
Do Until RS.EOF
%>
<tr>
<td><%=RS("Name")%></td>
<td><%=RS("Address")%></td>
<td><input type=checkbox name="ZAP" value="<%=RS("ID"%>"></td>
</tr>
<%
RS.MoveNext
Loop
%>
</table>
<input type=submit value="Delete checked people" name="DELETE">
</form>
</BODY></HTML>

Should have mentioned that this is all off the top of my head, utterly
untested. But it's warranted against bugs, anyway!

Guaranteed to be free of carpenter ants and dung beetles for 30 picoseconds
or 30 picometers, whichever comes first.
Aug 6 '08 #3


"Old Pedant" <Ol*******@discussions.microsoft.comwrote in message
news:92**********************************@microsof t.com...
Oh, what the heck...

Here's the code for adding a "CHECK ALL" button:

<HTML>
<HEAD>
<SCRIPT>
function checkAll( cbs )
{
if ( cbs.length == null )
{
// if only one checkbox
cbs.checked = true;
return; // only one to do
}
for ( var c = 0; c < cbs.length; ++c )
{
cbs[c].checked = true;
}
}
</SCRIPT>
</HEAD>
<BODY>
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "...your connection string..."

If Trim( Request("DELETE") ) <"" Then
' submit was pushed, delete all checked records
SQL = "DELETE FROM people WHERE id IN (" & Request("ZAP") & ")"
howMany = -1
conn.Execute SQL, howMany
Response.Write "<h2>Deleted " & howMany & " records</h2><P>"
End If
%>
<form method="POST">
<INPUT Type=Button Value="Check all" onClick="checkAll(this.form.ZAP);">
<table border=1 cellpadding=5>
<%
SQL = "SELECT ID, Name, Address FROM people"
Set RS = yourAlreadyOpenConnection.Execute( SQL )
Do Until RS.EOF
%>
<tr>
<td><%=RS("Name")%></td>
<td><%=RS("Address")%></td>
<td><input type=checkbox name="ZAP" value="<%=RS("ID"%>"></td>
</tr>
<%
RS.MoveNext
Loop
%>
</table>
<input type=submit value="Delete checked people" name="DELETE">
</form>
</BODY></HTML>

Should have mentioned that this is all off the top of my head, utterly
untested. But it's warranted against bugs, anyway!
What happens if there no records and the user presses the button ;)
--
Anthony Jones - MVP ASP/ASP.NET
Aug 6 '08 #4

"Anthony Jones" wrote:
What happens if there no records and the user presses the button ;)
Hey, that's what the warranty is for!!
Aug 6 '08 #5
Thank you both for your help! What I was looking to do when submitting
the page is to add all the records that are checked to an array, because
I will need to pass the information to another page and then populate a
dropdown with the email addresses of all the people who were checked on
the previous page.

Cheers,

Mike
*** Sent via Developersdex http://www.developersdex.com ***
Aug 7 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Adam Short | last post by:
I am trying to write a routine that will connect a .NET server with a classic ASP server. I know the following code doesn't work! The data is being returned as a dataset, however ASP does not...
3
by: Web Webon | last post by:
Hi everybody! I wonder if this is possible? I need to determine if a client is using "windows classic folders" or anything else. If I instantiate a Shell ActiveX object is there a way of...
5
by: Velvet | last post by:
Can someone tell me to what process I need to attach to be able to step through my classic ASP code in VS.net 2003. I'm working on an XP box with IIS installed. I also have VS.net 2005 (The...
4
by: pcnerd | last post by:
I originally asked this question in the "classic" VB forum. It occured to me after I had sent it that I sent it to the wrong forum. Anyway! Here's the situation. I have VB.NET 2005 Express...
2
by: theseandavis | last post by:
Hello, I am trying to sum together a number of rows by similarities that I have grouped together with the pull down menu. I would like to exclude one column if possible as it can be one of only...
9
by: Learner | last post by:
Hello , I am kinda new to VB 6.0. Is the line of code Private strCol(62, 2) As String declares a three dimensional array? Because in the code it is being used as strCol(1,0) = "x" strCol(2,0...
2
by: mosfet | last post by:
Hi, Recently I wrote some classes to list process, copy recursively files, delete files , ... and I have noticed that some part are common. For instance, copying or deleting folders always...
11
by: mase | last post by:
I've built a new ASP.NET web app with the CSLA framework. The site runs fine with a small number of users, but once there is any traffic the CPU spikes at 100%. I went through and made many updates...
12
by: mcp6453 | last post by:
My small company has a web site that is developed in "Classic ASP", which is, I'm told, different from just "ASP". It is clear to me that we are not using ASP.NET. The site is hosted on a shared...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.