Counting Checked Checked Boxes

1. Junior Member
Join Date
Dec 1969
Posts
22

Counting Checked Checked Boxes

I need to count the number of checkboxes checked on a form, so thtat I can tell my code to loop so many times<BR><BR>I&#039;m trying this code below, but if the first box is not checked, or non-sequential boxes aren&#039;t checked, I get an error.<BR><BR>Is there a way to do this:<BR><BR>i=1<BR>for each item in request.form<BR>if request.form("myRepeater:ctrl" & trim(str(i)) & ":approved") = "on" then<BR>abba=abba + 1<BR>end if<BR>ELSE<BR>abba=0<BR>end if<BR>i=i+1<BR>next

2. mj
Senior Member
Join Date
Dec 1969
Posts
848

RE: Counting Checked Checked Boxes

try this to start, also, if you are new to programming, here is a tip, don&#039;t use i for counter names, use something more descriptive, it&#039;ll help if you need to debug.<BR><BR>i=1<BR>for each item in request.form<BR>if trim(request.form("myRepeater:ctrl" & trim(str(i))) & ":approved") &#060;&#062;"" then<BR>abba=abba + 1<BR>end if<BR>ELSE<BR>abba=0<BR>end if<BR>i=i+1<BR>next<BR><BR>mj

3. Senior Member
Join Date
Dec 1969
Posts
96,118

Two problems...

(1) You have an extra END IF in the code you are showing us.<BR><BR>(2) If you *ever* get an unchecked box, your code sets the counter back to zero! So why are you surprised?<BR><BR>SIMPLIFY!<BR><BR>&#060;%<BR>cbCo unt = 0 &#039; no check boxes so far<BR>For whichCtrl = 1 To Request.Form.Count<BR>&nbsp; &nbsp If Request.Form("myRepeater:ctrl" & whichCtrl & ":approved") = "on" then <BR>&nbsp; &nbsp &nbsp; &nbsp cbCount = cbCount + 1<BR>&nbsp; &nbsp End If<BR>Next<BR>%&#062;<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
96,118

What did you change????

Sorry to pick on good old mj, but...<BR><BR>You still have the bogus extra END IF. You still have his counter (inexplicably named "abba") being reset to zero every time an "off" checkbox is found.<BR><BR>So I don&#039;t think you changed anything that mattered. Since he implied that under *some* conditions the code worked, I&#039;d guess that his test for ="on" is as valid as a test for &#060;&#062;"". No?<BR><BR><BR>

5. mj
Senior Member
Join Date
Dec 1969
Posts
848

RE: What did you change????

Just my underwear I guess :-p.<BR><BR>I didn&#039;t really look over the code that well, huh.<BR><BR>Trying to help as much as possible now, I start a new job as a Business Analyst for an Investment Banking company Monday, and the baby is due on Thursday, so I&#039;ll probably be gone from here for a little bit.<BR><BR>mj

6. Senior Member
Join Date
Dec 1969
Posts
96,118

Congratulations!

On both counts. I&#039;m envious of the first. Been there, done that on the second.<BR><BR>

7. mj
Senior Member
Join Date
Dec 1969
Posts
848

RE: Congratulations!

Thanks, I won&#039;t be doing much programming after about 6 months or so. My job will be to dream up new web/automation projects for the company and farm off the development requirements to the programmers.<BR><BR>I knew about the second one, I believe you kids are &#060;AgeYou&#062; right around my age, or a few years younger&#060;/AgeYou&#062;<BR><BR>I think I am more excited about the second one though, it will be totally new to me. <BR>The company that hired me, I actually worked for as a consultant for the last year.<BR><BR>mj

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•