I make a jQuery Chosen drop-down like this:
$(\'.blah\').chosen();
I can\'t find how I can add options, something like:
You can call this function to add element to chosen after you save the element to server using Ajax:
function appendToChosen(id,value){
$('.blah')
.append($('')
.val(id)
.attr('selected', 'selected')
.html(value)).trigger('liszt:updated');
}
Ajax call:
$.ajax({
type: 'POST',
url: 'savepage.php',
data: $('#modal-form form').serialize(),
success: function(data, status) {
appendToChosen(data[0],data[1]);
},
error: function (response) {
alert(response);
}
}).always(function(data, status) {
//hide loading
});