By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,212 Members | 2,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,212 IT Pros & Developers. It's quick & easy.

asp: values in array not in order??

P: n/a
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:

for each objItem in request.Form()
if left(objItem,3)="ck_" and request.Form(objItem) <> "" then
CkBoxArray=CkBoxArray & request.Form(objItem) & ","
end if
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!

This message is posted by

Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a

1. Let all the Check Boxes have the same name with different Values. Example:


2. On the receiving page, place the follow function in your asp code. Example

<SCRIPT language="javascript" runat="server">
function sortData(strData){
var data_array = strData.split(",");
return data_array.join();

'Here you are using VBScript inside the ASP Deliminators.
strSelectedItems = Trim(Request("DATA"))
If Len(strSelectedItems ) > 0 Then
strSelectedItems = sortData(strSelectedItems)
'Do What Ever
End If
d l b j r

Unambit from meager knowledge of inane others,
engender uncharted sagacity.
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.