Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP and Checkboxes 1

Status
Not open for further replies.

roy29

Instructor
Jun 12, 2000
17
US
I'm displaying a page with employees names and a checkbox to the left of each name. If the management checks the checkbox to the left of the employees name then that employee will be marked to be removed from the database. Every checkbox is given a unique identifier and the value property is set to the userid of the employee to delete. This page looks like the outlook asp pages that MS provides for remote access. I call another page that should process the checkboxes and delete the names however I'm having trouble figuring out how to see if the checkboxes have been checked and then getting the values from the checkboxes. Thanks for any help.
 
What I did was, I set a hidden input that holds the number of listed items. And I gave increasing numbers as the checkbox names i.e. box1 box2 ...

After the submission I read them one by one:

max_item = cint(request.form("max_item"))
for employee = 1 to max_item
current_employee = request.form("box"&employee)
if current_employee <> &quot;&quot; then 'was it checked? Update.
update_employee_database(current_employee)
end if
next
 
First off, name all your checkboxes the same.

<input type=&quot;checkbox&quot; name=&quot;DOdelete&quot; value=&quot;<%=rs(&quot;employeeID&quot;)%>&quot;>


Then on your second page:

the form DOdelete comes out like this:
1, 2, 3, 4


Now on the sql statement, im not sure if this way works, but you could give it a try. If not use the second example.
Code:
<%
Dim strChks

strChks = Request.Form(&quot;DOdelete&quot;)

If NOT Len(strChks) < 1 then

mySQL = &quot;DELETE FROM employees WHERE id IN (&quot; & strChks& &quot;)&quot;

End if
%>

Second way:

Code:
<%
Dim strChks, strChksSplit

'# Take out space
strChks = Replace(Request.Form(&quot;DOdelete&quot;), &quot;, &quot;,&quot;,&quot;)

'# Chk and see if there is a value
If NOT Len(strChks) < 1 then

'# split at comma
strChksSplit = Split(strChks,&quot;,&quot;)


For each Chk in strChksSplit 
mySQL = &quot;SELECT * FROM employee WHERE ID=&quot; & Chk
Next


End if
%>



-hope that helps
www.vzio.com
star.gif
/ [wink]
 
Try snowboardr's example, much more efficient, reliable and fast. Posting lots of object and reading them in a loop is not a good idea if you have 50+ inputs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top