0

I'm using chosen js lib:

<select class="chosen-select" name="country" id="country"  onchange="setCountry('client');">
   ...
</select>

Then i need change this select element:

$("#country").append('<option value="'+ countryid +'">' + countryname  + '</option>');
    

But it doesn't work with this lib and works without. How i can fix it? Thanks!

Community
  • 1
  • 1
  • Possible duplicate of [Adding options to a – Jonathan Gagne Oct 07 '18 at 17:38

2 Answers2

1

By using the below code you can attain your goal.

var currentelement = document.querySelector('#country');
        var newOptionElement = document.createElement("option");
        newOptionElement.text = "Test";
        currentelement.add(newOptionElement);
        var newOptionElement = document.createElement("option");
        newOptionElement.text = "Test1";
        currentelement.add(newOptionElement);
        var newOptionElement = document.createElement("option");
        newOptionElement.text = "Test2";
        currentelement.add(newOptionElement);
<select class="chosen-select" name="country" id="country">
    </select>
    var currentelement = document.querySelector('#country');
    var newOptionElement = document.createElement("option");
    newOptionElement.text = "Test";
    currentelement.add(newOptionElement);
0
$("#form_field").trigger("chosen:updated");

After editing element i must to use this code and it works