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 7676489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:12:40+00:00 2026-05-31T17:12:40+00:00

I have a multi-select box which has 2 buttons on the right which are

  • 0

I have a multi-select box which has 2 buttons on the right which are sorting an option up and down the list. This works fine, however if I move the option up or below the top or bottom boundary of the multiselect the scrollbar won’t take that into effect and move accordingly. Any suggestions?

JavaScript:

$(document).ready(function() {
  $("#mup")[0].attachEvent("onclick", moveUpItem);
  $("#mdown")[0].attachEvent("onclick", moveDownItem);
});

function moveUpItem() {
  $('#list option:selected').each(function() {
    $(this).insertBefore($(this).prev());
  });
}

function moveDownItem() {
  $('#list option:selected').each(function() {
    $(this).insertAfter($(this).next());
  });
}

//Holding down the Up/Down buttons
$(document).ready(function() {
  var timer;
  $("#mup, #mdown").on('mousedown', function() {
    if (this.id === 'mup') {
      timer = setInterval(moveUpItem, 250);
    } else {
      timer = setInterval(moveDownItem, 250);
    }
  }).on('mouseup', function() {
    clearInterval(timer);
  });
});

$(document).ready(function() {
  $("#submit").click(function() {
    $("#list").each(function() {
      $("#list option").attr("selected","selected");
    });
    $("#detColumnSortorder").submit;
  });
});

HTML:

<table>
  <tr>
    <td align="center">
      <select id="list" name="fieldNames" size="15" multiple="multiple" style="width: 250px;">
        <c:forEach var="field" items="${detFields}">
          <option value="${field.fieldName}">${field.displayName}</option>
        </c:forEach>
      </select>
    </td>
    <td>
      <button id="mup">
        <img src="../images/button_up.gif" alt="Hold to move up faster."/>
      </button>&nbsp;&nbsp;&nbsp;
    </td>
    <td>
      <button id="mdown">
        <img src="../images/button_down.gif" alt="Hold to move down faster."/>
      </button>
    </td>
  </tr>
  <tr>
    <td style="text-align: center;">
      <input name="action" id="submit" type="submit" value="Submit"/>
      <input name="action" type="submit" value="Cancel"/>
    </td>
  </tr>
</table>
  • 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-05-31T17:12:41+00:00Added an answer on May 31, 2026 at 5:12 pm

    Wow, this was interesting. It looks like there are some bugs with how Chrome/WebKit handle option movement in a select. I’m not entirely sure what the current behavior is. Sometimes it moves and sometimes it doesn’t.

    So, I thought, easy… I’ll just code a quick workaround. Turns out, it’s not so easy. WebKit doesn’t provide javascript access to some information, such as option height, etc.

    So, after quite a few workarounds I have a hack that seems to work:

    http://jsfiddle.net/jtbowden/7NEqk/

    Take it for what it is worth. Basically, the code tracks selected items within the visible window of the select box. If the top goes above the visible window, move up, etc.

    A couple of notes:

    1. You need to iterate through your selected options in reverse when you are moving down .get().reverse(), otherwise, if you have adjacent selected items, you will simply have them swap positions, instead of moving down. (1 moves below 2, then 2 moves below 1).
    2. If the browser does not return a height for the option element, I assume a height of 17. This is my best guess, but you could tweak it. Also, this means your options can’t be different heights. I don’t think that is possible in WebKit anyway.
    3. Before I move the selected item, I check if the item it is swapping with is selected. If it is, I don’t do the swap. This prevents the selections from swapping around when we get to the bottom or top of the select, where there is nothing to swap with. It’s similar to what I said in note #1, but a slightly different situation.
    4. I make the assumption that the selections all fit within the selection frame. It still works if they aren’t, but it could have been handled differently depending on what you wanted.
    5. I put return false; in the mousedown handler. This is the same as event.preventDefault(), etc. It keeps the button from stealing focus from the select, which in Chrome, makes the selected options turn gray, instead of their normal blue.

    Of course, after saying all of this, there is probably a better way of managing this select system in the first place… But, I took it as a challenge to make it work the way I thought it should.

    P.S. Who knows about IE… I didn’t check it, and I am afraid to.

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

Sidebar

Related Questions

I have a multi-select list-box with 100+ <option> Now I have 7 or 8
I have a multi-select list box. I want to be able to select a
Using Symfony and Doctrine, I have a multi-select list box. The multiple default values
I have a multi select box in a form. the elements in this select
I have multi-select drop down list where in user can select multiple options, now
I have a drop down that filters a multi-select box that then the user
I have the following multi-select box in a HTML form, where user can select
I have a multi-table query, similar to this (simplified version) SELECT columns, count(table2.rev_id) As
have an array of values [1,2,4] representing the values of a multi-select box, how
I have a multi-select listbox which I am binding to a DataTable. DataTable contains

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.