Skip to content

Instantly share code, notes, and snippets.

@cschlyter
Last active October 2, 2024 10:05
Show Gist options
  • Select an option

  • Save cschlyter/5187131 to your computer and use it in GitHub Desktop.

Select an option

Save cschlyter/5187131 to your computer and use it in GitHub Desktop.

Revisions

  1. cschlyter revised this gist Mar 21, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions sortSelectOption.js
    Original file line number Diff line number Diff line change
    @@ -4,8 +4,8 @@ function sortSelectOptions(selectElement) {
    options.sort(function(a,b) {
    if (a.text.toUpperCase() > b.text.toUpperCase()) return 1;
    else if (a.text.toUpperCase() < b.text.toUpperCase()) return -1;
    else return 0
    })
    else return 0;
    });

    $(selectElement).empty().append( options );
    }
  2. cschlyter renamed this gist Mar 18, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. cschlyter created this gist Mar 18, 2013.
    11 changes: 11 additions & 0 deletions sortSelectOption
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    function sortSelectOptions(selectElement) {
    var options = $(selectElement + " option");

    options.sort(function(a,b) {
    if (a.text.toUpperCase() > b.text.toUpperCase()) return 1;
    else if (a.text.toUpperCase() < b.text.toUpperCase()) return -1;
    else return 0
    })

    $(selectElement).empty().append( options );
    }