I have a HTML select dropdown with multiple
provided:
<select multiple id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
and assign a click handler which returns the currently clicked on elements' index:
document.getElementById("mySelect").onclick = function() {
alert(this.selectedIndex);
}
Which works fine when I select one of the elements only. But I want to return all indexes currently selected.
When I click Apple, Orange and Banana
a return like [0,1,3]
is what I want, but it does not work.
Working example: JSfiddle