Sort a DropDown Menu or SelectBox in Javascript

by Sasikumar 2014-06-07 23:34:37

Use the following function to sort dropdown menu,
function sortList(id) 
{
	var obj = document.getElementById("your_selectbox_id");
	var values = new Array();
	for(var i = 0; i < obj.options.length; i++) 
        {
		values.push(obj.options[i].innerHTML + "#SS#" + obj.options[i].value);
	}

	values = values.sort();

	for(var i = 0; i < values.length; i++) 
        {
		valueArray = values[i].split('#SS#');
		obj.options[i].innerHTML = valueArray[0];
		obj.options[i].value = valueArray[1];
	}
}
1002
like
0
dislike
0
mail
flag

You must LOGIN to add comments