View Full Version : Iterating through form fields

10-26-2003, 06:49 PM
I need to go through the rows on a form and see if a checkbox is checked. If so I need to get the value of a field in the same row. So it would be like this;

for each fld in request.form
If fld.name="OnOrOff" and fld.Value="True" Then
End If

I can't seem to find a reference to this. Is it possible?

10-26-2003, 07:17 PM
You need to include one unique value as part of all related formfields.

I gave an example here:

10-26-2003, 08:28 PM
Thanks Raf,

As usual you came through with exactly what I needed. Although I ended up doing it a little differently than your example. I wanted to be able to check several boxes, click done and have those checked deleted from my DB. What clued me in was your comment
Only checked boxes will be in the formscollection
I had misused the checkbox in my first attempt. I put my code here in case someone else has a similar problem. The form action calls this form so I look for records to delete, then requery the DB then paint the page.

Dim RS, SQL, dbCnxn, intCount
Call OpenConnection()
For intCount=1 to Request.Form("deleteMe").Count
SQL="DELETE FROM Users WHERE UserID=" & Request.Form("deleteMe")(intCount)
dbcnxn.Execute SQL
SQL="Select * FROM Users ORDER BY UserLName"
Set RS=dbcnxn.Execute(SQL)
%><form id="delUsrs" Name="delUsrs" action="delUser.asp" method="Post">
<table id="usrTbl" width="100%">
<th align="center">Del</th>
<th align="left">FirstName</th>
<th align="left">Last Name</th>
<th align="left">Screen Name</th>
While NOT (RS.EOF)
<td align="center"><input type="CheckBox" name="deleteMe" value="<% =RS("UserID") %>"></td>
<td><% =RS("UserFName") %></td><td><% =RS("UserLName") %></td>
<td><% =RS("UserHandle") %></td>
</tr><% RS.MoveNext
<td><input type="submit" value="Done"></td>