Switching items between listboxes, and letting .net realize it.

Discussion in 'ASP .Net' started by Ryan Ternier, Jul 23, 2004.

  1. Ryan Ternier

    Ryan Ternier Guest

    I have two listboxes, and allow users to move items between them via the
    following function:

    function SwitchList(fbox, tbox){
    var arrFbox = new Array();
    var arrTbox = new Array();
    var arrLookup = new Array();
    var i;
    for (i = 0; i < tbox.options.length; i++)
    {
    arrLookup[tbox.options.text] = tbox.options.value;
    arrTbox = tbox.options.text;
    }
    var fLength = 0;
    var tLength = arrTbox.length;
    for(i = 0; i < fbox.options.length; i++)
    {
    arrLookup[fbox.options.text] = fbox.options.value;
    if (fbox.options.selected && fbox.options.value != "")
    {
    arrTbox[tLength] = fbox.options.text;
    tLength++;
    }
    else
    {
    arrFbox[fLength] = fbox.options.text;
    fLength++;
    }
    }
    arrFbox.sort();
    arrTbox.sort();
    fbox.length = 0;
    tbox.length = 0;
    var c;
    for(c = 0; c < arrFbox.length; c++)
    {
    var no = new Option();
    no.value = arrLookup[arrFbox[c]];
    no.text = arrFbox[c];
    fbox[c] = no;
    }
    for(c = 0; c < arrTbox.length; c++)
    {
    var no = new Option();
    no.value = arrLookup[arrTbox[c]];
    no.text = arrTbox[c];
    tbox[c] = no;
    }
    }

    On the Client, the values do get switched between the listboxes, but
    whenever I run my javascript to access these listboxes and retrieve values,
    it retrieves ALL values that were initially loaded into it, and not the
    current ones.

    If anyone could shed some light, it'd be appreciated.

    Thank you.

    /RT
     
    Ryan Ternier, Jul 23, 2004
    #1
    1. Advertising

  2. "Ryan Ternier" <> wrote in message
    news:...
    > I have two listboxes, and allow users to move items between them via the
    > following function:


    <snip>

    > On the Client, the values do get switched between the listboxes, but
    > whenever I run my javascript to access these listboxes and retrieve

    values,
    > it retrieves ALL values that were initially loaded into it, and not the
    > current ones.
    >
    > If anyone could shed some light, it'd be appreciated.


    Your question is basically, "why doesn't the server know what happened on
    the client?" The answer is, "because the server is not the client".

    The only information which the server can know about the client is
    information which the client sends to the server. This information could be
    in a cookie, a URL query string, or in form POST data.

    In your example, I don't see any information being sent to the server, so
    the server won't know anything about it.

    You might want to use hidden fields to represent the data in the listboxes,
    one hidden field per listbox. The hidden fields could contain a
    comma-separated list of the items in the corresponding listbox. On the
    client, when an item is moved from one listbox to another, you would use
    JavaScript to remove one item from the origin hidden field and add it to the
    destination hidden field. The server would then be able to look in the
    hidden fields to see the current state.
    --
    John Saunders
    johnwsaundersiii at hotmail
     
    John Saunders, Jul 25, 2004
    #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. =?Utf-8?B?U2NvdXRMZWU=?=

    Pass Listitem between Listboxes

    =?Utf-8?B?U2NvdXRMZWU=?=, Sep 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    394
    =?Utf-8?B?U2NvdXRMZWU=?=
    Sep 20, 2004
  2. florin
    Replies:
    2
    Views:
    4,946
    Karl Seguin
    Mar 4, 2005
  3. Replies:
    0
    Views:
    316
  4. ASPirant

    moving items between two listboxes

    ASPirant, Nov 22, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    98
    ASPirant
    Nov 22, 2005
  5. AlBruAn
    Replies:
    1
    Views:
    103
    AlBruAn
    Jul 17, 2007
Loading...

Share This Page