| Programming C# C++ (7) Delphi (617) Java (8) JavaScript (31) Document (8) Events (8) ExtJS (9) Strings (3) perl (9) php (4) VBScript (1) Visual Basic (1)
New related comments Number of comments in the last 48 hours How to prompt the user with an inputbox in Javascript |
Sorting a SELECT listbox in Javascript
(18 votes). Leave comments and/ or rate it.
Question: What is the best way to sort a SELECT list box in Javascript?Answer: The following example assumes that your text and value tags are the same. In this case you can build an array of all the texts, use Javascript's built-in sort() function and the update the listbox.You don't even need to clear the listbox and then populate it again (which would be slower and possibly cause flickering). Instead you can update each entry directly. See the script live here (click on "Sort" below the list):
Comments:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||