I have the following code
function searchFlights() {
var select1 = document.getElementById(\"airports-select-1\");
var selected1 = [];
while(select1
Update for 2018:
If the element contains a
selectedOptions
property, use that collection. The only browser still in wide circulation that doesn't support this is IE (any version). Edge does support it.
If this is not supported, the answer by @j08691 is still correct, but as a performance optimization you can start iterating options at selectedIndex
instead of 0
. This is the index of the first selected option, or -1
if nothing is selected.