Print Page | Close Window

Have a loop to check all checked value

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=1847
Printed Date: 28 March 2026 at 11:13pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Have a loop to check all checked value
Posted By: ngaisteve1
Subject: Have a loop to check all checked value
Date Posted: 16 April 2003 at 2:42am
I am using the dynamic checkbox for my deletion. And the page which capture the all the checked id, I use sql = delete from [table-name] where id IN [all the check id]. The problem is my validation. In my first page, the records have a status field. This status field is actually a flag value, either pending or issued. But since the user all check any records (either the status is pending or issued), I need to validate this. I did have the validation but it is only the first record. How do validate all records? Meaning having a loop to check. If there is any records which status is issued, deletion cannot be performed. Otherwise, deletion can be performed. Hope everyone understand. Thanks



Replies:
Posted By: Coco Brown
Date Posted: 16 April 2003 at 12:04pm

Have the script keep a count of the number of records you loop through to create the records and the checkboxes.  Use the current count for part of the name for each row's checkbox.  Also have a hidden field named based off the current count whose value is the unique id of the record that the row represents.   Like id1,id2,id3 and cb1,cb2,cb3.  Have a hidden field at the end of the form that tells how many "rows" there are total.

i = 1
do while (orset.eof = false)
   response.write "<input type=""hidden"" name=""id" & i & """ value=""" & orset.fields("id") & """ />"
   response.write "<input type=""checkbox"" name=""cb" & i & """/>"
   response.write "<br />"
   i = i+1
   orset.movenext
next
response.write "<br />"
response.write "<input type=""hidden"" name=""totalCount"" value=""" & i & """ />"

Now do this when they submit

get the total from your hidden field at the end of the form.  Loop from the first number until the total.  Your script will probably look like this...

totalCount = request.form("totalCount")
for i=1 to totalCount
   if (request.form("cb" & i)  = "on") then 
      sql="DELETE * FROM myTable WHERE [id]=" & request.form("id" & i) & " AND [issued]=false;"
      conn.execute(sql)
   end if
next

If issued is false, that means it wasn't issued.  So even if the query finds the id, the id must also be pending.  Otherwise it is ignored.

You'll probably end up doing as many SQL deletes as there are records on a page.  So i'd keep pages small.  I haven't had a chance to test if the code itself is good, but the idea does work and it is how I create my dynamic forms this way.

Hopes this helps.    




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net