Results 1 to 3 of 3

Thread: Js - adding to a select listbox

  1. #1

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Js - adding to a select listbox

    last huge problem then this project's finished thank god !

    I have 2 <select> tags acting like vb listboxes on a web page. When a button's clicked, an entry (<option> tag) is taken out of the left select & put into the right select box.

    The problem is if you hold shift & multi - select entries. If these multiple entries are next to one another, they don't all copy over. If they aren't next to each other, then they all do copy over & I'm stumped becaus of this.

    Hopefully this code (not too big) should help & I've written some comments in to expain this better.

    Thanks All !
    Attached Files Attached Files

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  2. #2
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    They don't get added if they are adjacent because...

    Lets say you have five items, A, B, C, D, and E. A is the first item, so it has an index of 0. Let's say you have selected B, C and E.

    It cycles through starting with index 0.

    A is not selected.
    Next index. Index 1.
    B is selected.
    Add B to the right.
    Remove B from the Left
    Next Index. Index 2. Keep in mind that the left is now A, C, D, and E. So index 2 is the third item, that is now D, not C.
    D is not selected.
    Next index. Index 3.
    E is selected.
    Add E to the right.
    Remove E from the Left
    Next Index. Index 4. Index 4 exceeds the length, return from loop.

    If you want to immediately remove the item from the left, then subtract 1 from your index (index--), so when it adds one again, it will pick up the next one in the sequence (which has been shortened).
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  3. #3

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    You've been doing this a little while haven't you ;D

    YABADABADOO !!!!
    Thanks for that (think I'll keep that source handy for ajother time) - makes sense now you explained it, but I'd have never spotted that in a million years. Thanks again

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width