|
I have a form on an asp page and am trying to write the code to place the values of all checkboxes that have been selected, into an array. The checkbox values will be used in a dynamic sql statement to retrieve information from an access database, to be displayed ont he page. Since I`ve never worked with arrays before I`ve been running tests and displaying values on the next page to help me figure out my code.
my array code reads like this:
CkBoxArray="("
for each objItem in request.Form()
if left(objItem,3)="ck_" and request.Form(objItem) <> "" then
CkBoxArray=CkBoxArray & request.Form(objItem) & ","
end if
next
theLen=len(CkBoxArray)
CkBoxArray=left(CkBoxArray,theLen-1)
CkBoxArray=CkBoxArray & ")"
response.Write("CkBoxArray = " & CkBoxArray & "<br>")
The problem is, the values that are sent to the array aren`t in any logical order. I ran three separate tests and below is the output:
Since I know the values of each of the checkboxes, I made my selections by value for each test; then clicked submit.......
Example 1:
Selected values in this order: 2800,2000,1400,1000
Array received: 1000,1400,2000, 2800
Example 2:
Selected values in this order: 1000, 1200, 2200, 2800
Array received: 1000,1200,2200,2800
Example 3:
Selected values in this order: 1000,2200,2400,2800
Array received: 1000,2400,2200,2800
As you can see, Example 1 and 2 places the selected values in numerical order (which is what I want, otherwise I`ll have to move to the beginning of the file/table at the beginning of the loop) But, for a reason unknown to me, in the 3rd example the values aren`t in order. Is there another way for me to create my array so that the values are received in order (form.element instead of objItem in request.Form) or would I be better off just moving to the beginning of the table at the beginning of the loop (moveFirst)? I`m trying to run this in an efficient manner, but am learning as I go and not sure whats best. I`d appreciate anyone that could explain/help with this. Thanks a million!
|
|
|
|
|
|
|
|
|
// |