0

I am little bit confuse on how to apply sorting on dropdownlist in jquery

e.g apple,cat,truck,APPLE,CAT,TRUCK

it should be like in drop down list.... apple APPLE cat CAT truck TRUCK

how to achieve this in jquery so that it could see the uppercase and lowercase as well.

JN_newbie
  • 5,492
  • 14
  • 59
  • 97
  • I think this could help you http://javascript.about.com/library/blsort1.htm – Anton Oct 06 '12 at 16:45
  • Take a look at the answers for this Stack Overflow question: ["How to perform case insensitive sorting in Javascript?"](http://stackoverflow.com/questions/8996963/how-to-perform-case-insensitive-sorting-in-javascript). – Renato Zannon Oct 06 '12 at 16:46

1 Answers1

0

Lowering the case of items of array in custom sort method as below jsfiddle

var arr= [  "apple","cat","truck","APPLE","CAT","TRUCK"];

arr.sort(sort);
function sort(a, b){

   if(a.toLowerCase() > b.toLowerCase()) return 1;
       if(a.toLowerCase() < b.toLowerCase()) return -1;
    return 0;
}
Anoop
  • 23,044
  • 10
  • 62
  • 76