Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if a drop down has options to select?

How to tell if a drop down has options to select?

like image 238
Blankman Avatar asked Jan 31 '11 19:01

Blankman


People also ask

How do you define options in a drop-down list?

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.

How do I know which option is selected in HTML?

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).

How do you determine the selected value of an option?

If you want to get selected option value, you can use $(select element). val() .


3 Answers

if ($("#myselect option").length > 0) {
  // Yay we have options
}
like image 75
jessegavin Avatar answered Nov 03 '22 00:11

jessegavin


var menu = getElementById("select_id");
if(menu.options.length) {
    // has children
} else {
    // empty
}
like image 22
Makram Saleh Avatar answered Nov 02 '22 23:11

Makram Saleh


var hasOptions = !!$('#theSelect option').filter(function() { return !this.disabled; }).length;

maybe? This looks for <option> elements that are not disabled.

like image 42
Pointy Avatar answered Nov 02 '22 23:11

Pointy