Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Have a loop to check all checked value
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Have a loop to check all checked value

 Post Reply Post Reply
Author
ngaisteve1 View Drop Down
Groupie
Groupie
Avatar

Joined: 26 December 2002
Location: Malaysia
Status: Offline
Points: 169
Post Options Post Options   Thanks (0) Thanks(0)   Quote ngaisteve1 Quote  Post ReplyReply Direct Link To This Post Topic: Have a loop to check all checked value
    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
Back to Top
Coco Brown View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 April 2002
Location: United States
Status: Offline
Points: 245
Post Options Post Options   Thanks (0) Thanks(0)   Quote Coco Brown Quote  Post ReplyReply Direct Link To This Post 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.    

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.