Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Multiselect onblur method

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

like image 747
Gautam Avatar asked May 06 '26 21:05

Gautam


2 Answers

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

like image 78
Manse Avatar answered May 09 '26 10:05

Manse


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

like image 20
mitch Avatar answered May 09 '26 10:05

mitch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!