asp: values in array not in order??

S

Sue Adams

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!
 
D

dlbjr

Sue.

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

<INPUT TYPE=CHECKBOX NAME="DATA" VALUE="1000">1000<BR>
<INPUT TYPE=CHECKBOX NAME="DATA" VALUE="1200">1200<BR>
<INPUT TYPE=CHECKBOX NAME="DATA" VALUE="2200">2200<BR>
<INPUT TYPE=CHECKBOX NAME="DATA" VALUE="2800">2800<BR>

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(",");
data_array.sort();
return data_array.join();
}
</SCRIPT>

<%
'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
%>


HTH


-------------------------------------------------
d l b j r

Unambit from meager knowledge of inane others,
engender uncharted sagacity.
-------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top