chosen jquery not working dynamic html options

865 views Asked by At

I have two select dropdowns, When i change first select, onchange function will execute but options not updated in chosen 2nd dropdown. But options populated in orginal select.

Onchange function generate dynamic options for second select, when i inspect element original select updated, chosen results area not updated.

I follow below code.

 <select id="account" onchange="changePackage()">
 <select id="package">


  javascript
  $(select).chosen();

   $("#account"). on('change',function(){
    $("#package").trigger('chosen:updated');
1

There are 1 answers

0
Vaidas On

If I understand your question correctly, this should help you. You just need to add the callback function which will be executed after the select is updated:

function changePackage(){
    changePackageChosen(function(success) {
        if(success) {
            $("#package").trigger('chosen:updated');
        }
    });
}

function changePackageChosen(callback){
    /* binding options*/
    callback(true);
}