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

The Archive Base Latest Questions

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

I have a multi-select Box and I’m doing some javascript to sort the order

  • 0

I have a multi-select Box and I’m doing some javascript to sort the order of the elements in the box. I want to submit the whole array after sorting back to the Java and not just the select items. How can I achieve this?

JSP:

<script type="text/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());   
        });   
    }       
</script> 



<table width="100%">
    <tr>
        <td width="50%" align="center">
            <h1>DET Column Maintenance</h1>
        </td>
    </tr>
</table>

<form action="process.det_column_order" method="post" name="detColumnSortorder" >
    <table class="data_table">
        <tr align="center">
            <td>
                <select id="list" name="fieldNames" size="35" multiple="multiple" style="width: 250px;">
                    <c:forEach var="field" items="${detFields}">
                        <option value="${field.fieldName}">${field.displayName}</option>
                    </c:forEach>
                </select>
            </td>
        <tr>
            <td style="text-align: center;">
                <button id="mup">Move Up</button>&nbsp;&nbsp;&nbsp;
                <button id="mdown">Move Down</button>
            </td>
        </tr>
        <tr>
            <td style="text-align: center;">
                <input name="action" type="submit" value="Submit"/>
            </td>
        </tr>
     </table>   
 </form>

FORM:

 private String[] fieldNames;
public String[] getFieldNames() { return this.fieldNames; }
            public void setFieldNames(String[] val) { this.fieldNames = val; }
  • 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-31T06:12:24+00:00Added an answer on May 31, 2026 at 6:12 am

    Since forms only submit the selected values, you’ll need a little more JS and another form field.

    Introduce a hidden form field that will hold the values you care about:

    <input type="hidden" name="fieldNamesOrder" id="fieldNamesOrder"/>
    

    And after every click of Move Up/Move Down:

    var order = [], sel = document.getElementById("list");
    for(var i = 0, len = sel.options.length; i < len; i++) {
        order.push(sel.options(i).value);
    }
    document.getElementById("fieldNamesOrder").value = order.join(",");
    

    Then, on the server side, you can read your ordered field names out of that posted field.

    • 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. I want to be able to select a
have an array of values [1,2,4] representing the values of a multi-select box, how
I have a multi select box in a form. the elements in this select
I do have a multi select dropdown box. I want all the selected items
I have the following multi-select box in a HTML form, where user can select
I have a multi-select <asp:listbox> and a button. I want to disable the button
Using Symfony and Doctrine, I have a multi-select list box. The multiple default values
I have a problem with the multi-select box. I tried to select multiple values
I have a multi-select list-box with 100+ <option> Now I have 7 or 8
I have the following multi select box in a HTML form: <select multiple=multiple name=fruits>

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.