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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop thru QueryString

Status
Not open for further replies.

davman2002

Programmer
Nov 4, 2002
75
US
I want to know if anyone know how to loop thru a querystring of Checkboxes and determine which ones have been checked? What I actually want to do is determine which checkboxes have been selected and then based on that information update the database.
Here is what I currently have and it does not seem to work

<%
strB1(0) = Request.QueryString(&quot;B1&quot;)
strB1(1) = Request.QueryString(&quot;B2&quot;)
strB1(2) = Request.QueryString(&quot;B3&quot;)
strB1(3) = Request.QueryString(&quot;B4&quot;)
strB1(4) = Request.QueryString(&quot;B5&quot;)
strB1(5) = Request.QueryString(&quot;B6&quot;)
strB1(6) = Request.QueryString(&quot;B7&quot;)
strB1(7) = Request.QueryString(&quot;B8&quot;)
strB1(8) = Request.QueryString(&quot;B9&quot;)
strB1(9) = Request.QueryString(&quot;B10&quot;)
strB1(10) = Request.QueryString(&quot;B11&quot;)
strB1(11) = Request.QueryString(&quot;B12&quot;)
strB1(12) = Request.QueryString(&quot;B13&quot;)
strB1(13) = Request.QueryString(&quot;B14&quot;)
strB1(14) = Request.QueryString(&quot;B15&quot;)
strB1(15) = Request.QueryString(&quot;B16&quot;)


'Determine which Basic Information buttons were checked

BCounter = 0
Counter = 0

While Counter < 16

If strB1(Counter) = &quot;ON&quot; Then
If Counter = 0 Then
MyArray = strB1(Counter)
Else
MyArray = MyArray & &quot;,&quot; & strB1(Counter)
End If
End If
Counter = Counter + 1
BCounter = BCounter + 1
Wend

strB_info = Array(MyArray)

'Used for testing
Response.Write MyArray
%>
 
Well, firstly, only the ones that were checked will be passed, but since you are referncing each one as a string what you can do is build a for loop (if you know how many there are) and build those checkbox query names dynamically, like so:
Code:
For i = 0 to 10
   strB(i) = Request.QueryString(&quot;B&quot;&i)
Next

Anothe method is to loop through all the values that were passed in the querystring and then only grab the B's. I would deem this to be less efficient however, as you will be checking every single input that was passed and have to check if it is a B than grab the number off of the name.

Hope this helps,
-Tarwn ________________________________________________
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
Thanks, I had to make a few modifications but it works great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top