I am trying to figure out how to get selected options from ajax-Chosen plugin with no luck.
This is my html:
<select multiple='multiple' class='chzn-select' data-placeholder='users'>
<option value='0' selected>username1</option>
<option value='1' selected>username2</option>
</select>
And this is JS part:
$(".chzn-select").ajaxChosen({
method: 'GET',
url: 'users.php',
dataType: 'json',
minTermLength: 3,
afterTypeDelay: 300
}, function (data) {
var terms = {};
$.each(data, function (i, val) {
terms[i] = val;
});
return terms;
});
This all works fine. But when I remove one option "username2" the select field does not get updated. So when I want to get all selected users from list I get wrong list - in this case I always get both values even that one was removed from list.
I've also tried to trigger update with no luck:
$(".chzn-select").trigger("liszt:updated");
Does anyone have a suggestion how to get real values from select list?
Just found a solution thanks to stof:
Instead of $(".chosen-select option").each();
I did this: $(".chosen-select).val();