Order select options - Javascript

Order select options - Javascript

code snippet

javascript
function ordercollectionlist(){
	var options = jQuery('#selectid option');
	var arr = options.map(function(_, o) { return { t: jQuery(o).text(), v: o.value }; }).get();
	arr.sort(function(o1, o2) {
		if (o1.t.toLowerCase()=='select'){return -1;}
		var t1 = o1.t.toLowerCase(), t2 = o2.t.toLowerCase();return t1 > t2 ? 1 : t1 < t2 ? -1 : 0;}
	);
	options.each(function(i, o) {
		o.value = arr[i].v;
		jQuery(o).text(arr[i].t);
	});
}

"It is never too late to be what you might have been"

Contact me!

Have questions? Feel free to use the form or send me an email with any questions.

I will be responsive to your requests and your questions.