/ Published in: JavaScript
Takes a select box ID and sorts the values - maintains key index pairs.
Expand |
Embed | Plain Text
function sortList(id) { var obj = document.getElementById("id"); var values = new Array(); for(var i = 0; i < obj.options.length; i++) { values.push(obj.options[i].innerHTML + "--xx--" + obj.options[i].value); } values = values.sort(); for(var i = 0; i < values.length; i++) { valueArray = values[i].split('--xx--'); obj.options[i].innerHTML = valueArray[0]; obj.options[i].value = valueArray[1]; } }
You need to login to post a comment.
