/ Published in: JavaScript
Author: Clyde Ingram
Expand |
Embed | Plain Text
function compareOptionText(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 sortOptions(list) { 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(compareOptionText); // 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); }
Comments
Subscribe to comments
You need to login to post a comment.

Very good! After a lo000ooooong search I found here what I needed! Thanks a lot