John
John

Reputation: 21927

automatically select option if only one in selectbox list - JQuery

I am using this as a way to filter a select box. I want to extend it so that if there is only one option left it is automatically selected. Can anyone help me with this?

Upvotes: 2

Views: 3114

Answers (1)

Tgr
Tgr

Reputation: 28160

if ($j('#selectList option:visible').length == 1) {
    $j('#selectList option:visible').attr('selected', true);
}

Upvotes: 4

Related Questions