views:

260

answers:

1

I have a form with multiple dropdownlists on it. Some of them possess multiple values, others posess a blank choice and another random choice.

Using jQuery how do I detect which dropdowns have the blank choice selected AND have only one other choice THEN select that other choice.

I got the selector part down,

$("[id*='_ddl']").each(function() {

but am not sure how to detect the number of choices available, and if the currently selected value is a blank.

Thanks!

+1  A: 
$('select[id*=_ddl]').each(function() {
    var itemCount = $('option', this).length;
    var selectedText = $('option:selected', this).text();
    if (selectedText.length === 0 && itemCount === 2) {
        // do stuff
    }
});
Ken Browning
replace // do stuffwith $(this).get(0).selectedIndex = 1; to select the non blank elemen
bulltorious