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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:28:52+00:00 2026-06-07T18:28:52+00:00

I fund a very nice sorting function here How may I sort a list

  • 0

I fund a very nice sorting function here
How may I sort a list alphabetically using jQuery?
works almost perfect except that it looks like sorts by first charachter only , for example
if you have something like

0-5000
5001-10000
10001-15000
15001-20000

the order will look like

0-5000
10001-15000
15001-20000
5001-10000

instead

0-5000
5001-10000
10001-15000
15001-20000

I redid the function for every select in the form

var mylist = $('#myformid select');

$(mylist).each(function (sorter, elm) { 
  var listitems = $(this).children('option.myoptionclass').get();
   listitems.sort(function(a, b) {
      var compA = $(a).text().toUpperCase();
      var compB = $(b).text().toUpperCase();
      return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
   })
     $.each(listitems, function(idx, itm) { 
          $(this).parent().append(itm); 
      });

});

here is live example

http://jsfiddle.net/sQsZQ/6/

any help is welcome!

  • 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-07T18:28:53+00:00Added an answer on June 7, 2026 at 6:28 pm

    I editted your fiddle: http://jsfiddle.net/CBD33/2/
    I’m using parseInt so the comparison looks like this now:

    listitems.sort(function(a, b) {
      var compA = $(a).text().toUpperCase();
      var compB = $(b).text().toUpperCase();
      compA = (parseInt(compA,10) || compA)
      compB = (parseInt(compB,10) || compB)              
    
    
      return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
    })
    

    If the first character of the string value given to parseInt is a numeral, it will parse everything up to the first non-digit character. If the first character isn’t a numeral, it’ll return NaN. My use of || there is rather lazy, but I’m sure you can come up with a better condition.

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

Sidebar

Related Questions

Fund few functions to sort array but none of them can sort them if
I am implementing two dropdown lists where Fund dropdown list is populated by the
I have this code to return a list of fund sources for our organization.
I fund and inserted this code in my FTP in a backup.php that works
I have a content type called fund. The contents of this is in node-fund.tpl.php
I have a requirement to use a Fund model in my code. It will
Ive looked for some examples online but i couldn't fund any. how can i
I'm doing some work for a charity that's having a fund drive. Whenever someone
I have public class FundController { private Site _site; public ViewResult Fund() { }
I have the following XML: <PerformancePanel page=PerformancePanel.ascx title=> <FundGroup heading=Net Life Managed Funds> <fund

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.