I have to add options into my dropdown with ajax call in jquery's multiselect-filter dropdown.
this is my jsfiddle
I do not have to show any data in dropdown until user type something in filter. The time user type anything in filter box, one ajax call will be made and dropdown will be populated. I am fine with ajax call but how to add new options into dropdown.
I have tried all below options to add options into my dropdown.
1) From here I got the idea source. This is going in an infinite loop.
var el = $("#id").multiselect();
$("#id").multiselect().multiselectfilter({
filter: function(event, matches){
var v = "val", opt = $('<option />', {
value: v,
text: v
});
opt.appendTo( el );
el.multiselect('refresh');
}
});
2) From here I got the idea source
var myOptions = {
val1 : 'text1',
val2 : 'text2'
};
var mySelect = $('#mySelect');
$.each(myOptions, function(val, text) {
mySelect.append(
$('<option></option>').val(val).html(text)
);
});
and few more with little changes here and there. Please suggest.
EDIT
Or is there any way to hide all options from the dropdown and show them only when filter matches with any of them!!!