How to tell if a drop down has options to select?
To include an option in a drop-down list, use the <option> tag in HTML. The HTML <option> tag is used within a form for defining options in the drop-down list.
The selectedIndex property sets or returns the index of the selected option in a drop-down list. The index starts at 0. Note: If the drop-down list allows multiple selections it will only return the index of the first option selected. Note: The value "-1" will deselect all options (if any).
If you want to get selected option value, you can use $(select element). val() .
if ($("#myselect option").length > 0) {
// Yay we have options
}
var menu = getElementById("select_id");
if(menu.options.length) {
// has children
} else {
// empty
}
var hasOptions = !!$('#theSelect option').filter(function() { return !this.disabled; }).length;
maybe? This looks for <option>
elements that are not disabled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With