Listbox in Javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • malav123
    New Member
    • Feb 2008
    • 217

    Listbox in Javascript

    HI,
    I am using two listboxes in asp.net and i am using javascript for moving items from one list box to another but when i am trying to move all items from one listbox to another listbox then not all the items moves from one listbox to another but only some items removes and moves so can you give me suggestion for my problem... my code is given below....
    [code=javascript]
    if(id=="ctl00_C ontentPlaceHold er1_TabAddCompa ny_TabPanel1_bt nnextall")
    {
    var i = 0;
    for (i = 0; i <= lstavailablesta te.length - 1; i++)
    {
    var newOption = new Option(); // Create a new instance of ListItem
    newOption.text = lstavailablesta te.options[i].text;
    newOption.value = lstavailablesta te.options[i].value;

    lstassociatedst ate.options[i] = newOption; //Append the item in Target
    hid = hid + lstavailablesta te.options[i].value + ",";
    lstavailablesta te.remove(i); //Remove the item from Source
    }

    }
    [/code]
    awaiting for reply...
    thanks in advance......
    Last edited by Frinavale; Mar 18 '08, 07:23 PM. Reason: added [code] tags
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by malav123
    HI,
    I am using two listboxes in asp.net and i am using javascript for moving items from one list box to another but when i am trying to move all items from one listbox to another listbox then not all the items moves from one listbox to another but only some items removes and moves so can you give me suggestion for my problem... my code is given below....
    [code=javascript]
    if(id=="ctl00_C ontentPlaceHold er1_TabAddCompa ny_TabPanel1_bt nnextall")
    {
    var i = 0;
    for (i = 0; i <= lstavailablesta te.length - 1; i++)
    {
    var newOption = new Option(); // Create a new instance of ListItem
    newOption.text = lstavailablesta te.options[i].text;
    newOption.value = lstavailablesta te.options[i].value;

    lstassociatedst ate.options[i] = newOption; //Append the item in Target
    hid = hid + lstavailablesta te.options[i].value + ",";
    lstavailablesta te.remove(i); //Remove the item from Source
    }

    }
    [/code]
    awaiting for reply...
    thanks in advance......
    Do you know in what cases the values are "sometimes not moved" correctly?
    Is it when it is the first item in the list?
    Is it when it is the last item in the list?
    Is it in the middle?

    There should be some pattern as to why this is not working "sometimes" .

    -Frinny

    Comment

    • malav123
      New Member
      • Feb 2008
      • 217

      #3
      thanks for reply...
      and i got solution of my problem....
      i made two seprate loop then it is working now properly...
      again thanks for response.....

      Comment

      Working...