Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8243985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:41:42+00:00 2026-06-07T21:41:42+00:00

I have an application with nearly 70 items in a <select> that allow multiple

  • 0

I have an application with nearly 70 items in a <select> that allow multiple selection.

I’m trying to replace its behavior by two lists, where the user can drag/drop between a source list to a target list. The initial select should reflect the moves.

I’m trying to make it generic because I have to reuse the behavior in several pages, sometimes several times in the same page.

What I have by now (I reduced the actual number of items for readability) :

<div style="border: solid 1px red; overflow:auto">
    <select name="lst1" multiple="multiple" id="lst1" class="go">
        <option value="1">Element N°1</option>
        <option value="2">Element N°2</option>
        <option selected="selected" value="3">Element N°3</option>
        <option value="4">Element N°4</option>
        <option value="5">Element N°5</option>
    </select>
</div>

<script type="text/javascript">
    $(function () {
        $(".go").each(function (index, el) {
            var source = document.createElement("ul");
            var target = document.createElement("ul");
            $(el).after(source);
            $(el).after(target);
            $(source).addClass("sourceItems");
            $(target).addClass("targetItems");
            $(el + "option:selected").each(function (index2, sub) {
                var item = document.createElement("li");
                item.textContent = $(sub).text();
                $(target).append(item);
            });
            $(el + "option:not(:selected)").each(function (index2, sub) {
                var item = document.createElement("li");
                item.textContent = $(sub).text();
                $(source).append(item);
            });

            $(source).sortable({ connectWith : target});
            $(target).sortable({ connectWith : source });
        });
    });

</script>

<style type="text/css">    
.sourceItems, .targetItems { list-style-type: none; float:left; margin: 0; padding: 0; margin-right: 10px; background: #eee; padding: 5px; width: 200px; border: solid 1px black; } 
.sourceItems li, .targetItems li { margin: 5px; padding: 5px; width: 180px; height: 12px; cursor: move; }
</style>

This code is producing unexpected result :

enter image description here

The “target” list’s generated DOM looks like ok :

<ul class="targetItems ui-sortable">
<li>Element N°3</li>
<li>Element N°7</li>
<li>Element N°8</li>
<li>Element N°14</li>
<li>Element N°20</li>
<li>Element N°15</li>
<li>Element N°21</li>
</ul>

but the “source” list’s generated DOM is a mess (it contains the page DOM in each element)):

<li>
    .sourceItems, .targetItems { list-style-type: none; float:left; margin: 0; padding: 0; margin-right: 10px; background: #eee; padding: 5px; width: 200px; border: solid 1px black; } 
    .sourceItems li, .targetItems li { margin: 5px; padding: 5px; width: 180px; height: 12px; cursor: move; }
</li><li>

</li><li></li><li>
    .sourceItems, .targetItems { list-style-type: none; float:left; margin: 0; padding: 0; margin-right: 10px; background: #eee; padding: 5px; width: 200px; border: solid 1px black; } 
    .sourceItems li, .targetItems li { margin: 5px; padding: 5px; width: 180px; height: 12px; cursor: move; }

    Element N°1
    Element N°2
    Element N°3
    Element N°4
    Element N°5
    Element N°6
    Element N°7
    Element N°8
    Element N°9

...

Element N°3Element N°7Element N°8Element N°14Element N°15Element N°20Element N°21Element N°23Element N°27Element N°29Element.

I can’t see what’s wrong. I’d appreciate someone points me the root of the issue.

Here is a jsfiddle that show the issue : http://jsfiddle.net/gsYHb/

[edit] If i reverse the order of creating the source and target elements, the problem occurs on the other list :

        var source = document.createElement("ul");
        var target = document.createElement("ul");
        $(el).after(target);
        $(el).after(source);

in this case, this is the target list that is messy.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:41:43+00:00Added an answer on June 7, 2026 at 9:41 pm

    As you will see in http://jsfiddle.net/stevebeauge/gsYHb/6/, I have been able to solve my issue.

    It was due to the $(this + "option:not(:selected)") selector that was returning the whole page.

    Replacing this code with $(this).children("option:not(:selected)") make the script works (+ some other minor fixes)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building an application that can have multiple users from multiple accounts. For
I have a multi-tenancy application that I am developing and I'm nearly there. Currently
I have an application running on Websphere Application Server 6.0 and it crashes nearly
I have application that makes different queries with different results so the caching in
I have application that is connecting to the DB and if I enter incorrect
I have application that is up more than 3 days. I can see in
I have Application X with Subform x1, x2, x3. The Subform has, because its
I'm nearly ready to distribute my vb.net application. I have several picturebox files which
We have an enterpise web application that did consist of 4 compiled components (DLLs).
The setup I have an MVC application that's making AJAX requests into my controller.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.