seanybravo
IS-IT--Management
I have Employee banding in a Select list that is part of a pick list i.e. 1-10, 11-25 etc. But I am having a nightmare on sorting it. I initially load the select list in order but when things are moved about in the select list the order gets changed. Here is the code I have been working on. I am new to sorting so I am struggling a bit.
Any help would be appreciated.
Thanks
Sean
Here is an example of the employee banding
1-9
10-24
25-49
50-99
100-199
200+
Any help would be appreciated.
Thanks
Sean
Code:
function compareOptionNumber(a,b) {
/*
* return >0 if a>b
* 0 if a=b
* <0 if a<b
*/
// textual comparison
//return a.text!=b.text ? a.text<b.text ? -1 : 1 : 0;
// numerical comparison
return a.text - b.text
}
function sortOptionsN(list) {
//alert("employees")
var items = list.options.length;
// create array and make copies of options in list
var tmpArray = new Array(items);
for ( i=0; i<items; i++ )
tmpArray[i] = new
Option(list.options[i].text,list.options[i].value);
// sort options using given function
tmpArray.sort(compareOptionNumber);
// make copies of sorted options back to list
for ( i=0; i<items; i++ )
list.options[i] = new Option(tmpArray[i].text,tmpArray[i].value);
}
Here is an example of the employee banding
1-9
10-24
25-49
50-99
100-199
200+