How can I get the values selected in the drop-down list, using a JavaScript function? User can select multiple values from both the elements. Following are the elements
var fld = document.getElementById('icOptions');
var values = [];
for (var i = 0; i < fld.options.length; i++) {
if (fld.options[i].selected) {
values.push(fld.options[i].value);
}
}
// do something with values
An ES6/functional style alternative to the accepted answer:
const values = Array.apply(null, e.target.options)
.filter(option => option.selected)
.map(option => option.value);
Really Awesome Library for your need using jQuery or Prototype http://harvesthq.github.com/chosen/ Have a look at it.
It supports select & multiselect in a really nice way