1

I have a list box lstPresentRates that displays

<option value="1.01">(I)Ally Bank-Internet (1.01)</option>
<option value="1.03">(I)Alostar Bank-Internet (1.03)</option>
<option value="0.55">(I)American Express Bank-Salt Lak (0.55)</option>

I would like to sort on value on a button click event.

I tried this but it's apparently not quite right -

$('#lstSelectRates'.value.sort());

MC

1

2 Answers 2

3
var opt = $('select option');
    opt.sort(function(a, b) {
        if(parseFloat($(a).attr('value')) > parseFloat($(b).attr('value')))
            return 1;
        else return -1;
    });
    $('select').empty().html(opt);
Sign up to request clarification or add additional context in comments.

Comments

2

Here is a jsfiddle

var $sel = $('#lstSelectRates');
var $children= $sel.children('option').sort(function(a,b){
                                          a=$(a).attr("value")*1.0;
                                          b=$(b).attr("value")*1.0;
                                          return a > b ? 1 : -1;});

$sel.empty();
$children.appendTo($sel);​

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.