How can i call onblur method on jquery mutiselect? Like in my multiselect i have below values if user select red and green then based on that i need to fetch data from db
<select multiple="multiple" id="myID" name="myName">
<option value="blue">blue</option>
<option value="red">red</option>
<option value="green">green</option>
</select>
I tried click function but that can send only one option value at a time so looking for onblur like of function in jquery multiselect or any event that triggers after selecting all the values from multiselect i mean if user click outside multiselect.
thanks in advance.any help would be much appreciated
Use the .blur() method
var selectedvals = [];
$('#myID').blur(function() {
$('#myID > option:selected').each(function(i, selected) {
selectedvals.push($(selected).val());
});
})
the selectedvals array contains the values from the selected options
Working example here
Using JQuery 1.7.1
$('#myID').on('blur', function(){
var selected=[];
$(this).find('option:selected').each(function(i,e){
selected.push(e.value);
});
alert('You selected: ' +selected.join(','));
});
Here is the example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With