Question

So I've read the other question about this and I can't seem to get it to work. I have this HTML:

    <select name="filter" id="filter" multiple="multiple" data-native-menu="false">
    <option>Choose Filter</option>
    <option value="Matt"> Matt</option>
    <option value="Brian"> Brian </option>
    </select>

Yet using this code:

    $("#filter").val()

Returns me an empty string, even when options are selected.

Was it helpful?

Solution

$('#filter').change(function(){
    var selectedValues = $(this).find('option:selected').map(function(){
                             return this.value;
                         }).get();
    console.log(selectedValues);
});

JS Fiddle demo.

References:

OTHER TIPS

Try this.

$('option:selected','#filter').html()

try this

 $("#filter option:selected").val();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top