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

  • Home
  • SEARCH
  • 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 9096587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:53:28+00:00 2026-06-16T23:53:28+00:00

I have created a list box like this, and created a title bar which

  • 0

I have created a list box like this, and created a title bar which helps to sort data:

ID                 Name
------------------------------------------------------------
ID1                Identity One
ID2                Identity Two
ID3                Identity Three
ID4                Identity Four
-------------------------------------------------------------

I have a requirement to sort above list based on ID and also on Name, means when user clicks ID, it should sort list based on ID and vice versa. But the problem is from data layer we are getting like this in a single line:

ID1   &nbsp:Idenitity One

So we are printing the same in options tag, and getting output like above. Code to generate above output is:

 <select id="selSort" size="10" style="width:350px" id="rpt">
<option value = "ID1">
        ID1 &nbsp; &nbsp; Identity One
</option>
<option value = "ID2">
        ID2 &nbsp; &nbsp; Identity Two
</option>
<option value = "ID4">
        ID4 &nbsp; &nbsp; Identity Four
</option>
<option value = "ID3">
        ID3 &nbsp; &nbsp; Identity Three
</option>

My question is how do I implement sorting facility for above scenario? Yes, I tried to sort, but it is sorting entire list box, not based on single value. At-least now what can I do is format incoming data such way that put all Ids in one array and names in another, so any guide/pointers on this appreciated. Please let me know if I haven’t explained clearly

EDIT:

Code I tried to sort a list box

function sortSelect(selElem) {
    var tmpAry = new Array();
    for (var i=0;i<selElem.options.length;i++) {
        tmpAry[i] = new Array();
        tmpAry[i][0] = selElem.options[i].text;
        tmpAry[i][1] = selElem.options[i].value;
    }
    tmpAry.sort();
    while (selElem.options.length > 0) {
        selElem.options[0] = null;
    }
    for (var i=0;i<tmpAry.length;i++) {
        var op = new Option(tmpAry[i][0], tmpAry[i][1]);
        selElem.options[i] = op;
    }
    return;
}
  • 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-16T23:53:29+00:00Added an answer on June 16, 2026 at 11:53 pm

    You can use the custom array sort take a look at this How to sort select base on an id ?

    The idea here is just create a arrray and sort that based on its value and than dynamically create the option based on the sorted value.

    Custom sorting code

    source.sort(function (x, y) {
      if (isAsc) 
         return y.id - x.id;
      else 
        return x.id - y.id;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a list box which is multiple selectable as below: <td rowspan=20>
I have created a unbound listbox. I have the box showing a list of
i have a class which looks like this public class Process_Items { String Process_Name;
I have a list of items, created by a listview. I would like to
I have a select box like <select id=addressbook_user name=addressboook_user> <?php $asql = SELECT *
I have created one listview, in this each row contain check box and the
I have created a list view that displays the names and dates of items
I have created a list form that gets attached to a main form in
I have created a custom list as a feature in sharepoint. i need to
I have created a dynamic list picker script using Jquery 1.3 and PHP that

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.