asp: values in array not in order??

Discussion in 'ASP General' started by Sue Adams, Aug 16, 2003.

  1. Sue Adams

    Sue Adams Guest

    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!

    -----------------------------
    This message is posted by http://Asp.ForumsZone.com
    Sue Adams, Aug 16, 2003
    #1
    1. Advertising

  2. Sue Adams

    dlbjr Guest

    Re: values in array not in order??

    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.
    -------------------------------------------------
    dlbjr, Aug 16, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Soren Kuula
    Replies:
    2
    Views:
    481
    Soren Kuula
    Feb 1, 2004
  2. Replies:
    6
    Views:
    498
    bugbear
    Nov 17, 2006
  3. cspoh
    Replies:
    0
    Views:
    233
    cspoh
    Jul 31, 2003
  4. Stephan Kämper
    Replies:
    2
    Views:
    227
    Stephan Kämper
    Jan 18, 2004
  5. Tuxedo
    Replies:
    8
    Views:
    125
    Tuxedo
    May 7, 2007
Loading...

Share This Page