Reputation: 266978
How to tell if a drop down has options to select?
Upvotes: 13
Views: 17191
Reputation: 55392
Very hackily, you can just check its selectedIndex; since most browsers ensure that there is something selected if at all possible, it will only be -1 if there are no selectable options.
Upvotes: 0
Reputation: 75650
if ($("#myselect option").length > 0) {
// Yay we have options
}
Upvotes: 10
Reputation: 303206
if ($("#myselect option:enabled").length){
// Yay!
}else{
// Oh, no available options
}
http://api.jquery.com/enabled-selector/
Upvotes: 2
Reputation: 105220
Native javascript solution:
!!document.getElementById('jiveviewthreadsform-filter').children.length
(Please do not overuse jQuery, thanks)
Upvotes: 0
Reputation: 13921
$('#input1 option').length > 0
Where #input
is the ID of the select
element you are running this test against.
Upvotes: 3
Reputation: 8701
var menu = getElementById("select_id");
if(menu.options.length) {
// has children
} else {
// empty
}
Upvotes: 15
Reputation: 413712
var hasOptions = !!$('#theSelect option').filter(function() { return !this.disabled; }).length;
maybe? This looks for <option>
elements that are not disabled.
Upvotes: 8