Reputation: 2814
I have a combobox which on change triggers an ajax call and fetches a few values. These values are used to create another combobox.
The code below is used to dynamically load the options of the combobox:
function appendOption(select,option) {
try {
alert(select.innerHTML+"--select--"+option.innerHTML+"--option");
alert(select.add(option, null)); // shows the option tag formed
select.add(option, null); // not adding the option element into the combo
} catch (e) {
alert(e.message());
}
}
The select object inside the method is also a valid object.
I have used chosen-select
jquery plugin for creating this combo box. But the above method is working fine in case of normal combo (not chosen-select).
Can anyone please help me?
Upvotes: 1
Views: 386
Reputation: 695
If your problem is "select control not populating with added option" then you need to add
$('.my_select_box').trigger('chosen:updated');
method once you finish adding options.
In your case after add method.
Chosen control need to told about changes you made with them.So by calling above update trigger tells chosen that control is changed so re render it.
Upvotes: 1