Q:

change select option in django via javascript

I have the following issue :
1/ Using Django, I am generating a form containing a set of countries.
The form is as follows :
country=forms.CharField(max_length=20
                     , widget=forms.Select(choices=countries)
                     , label=_('Country'))

The generated html is as follows
<div class="form-group">
   <label class="col-lg-1" for="id_country"> … </label>
   <div class="col-lg-1">
      <select id="id_country" class="chzn-done" name="country" style="display: none;"> … </select>
      <div id="id_country_chzn" class="chzn-container chzn-container-single" style="width: 291px;" title=""> 
   </div>
</div>
</div>

2- I'd like to update the select dynamically using javascript
The code to update the select is provided below. The option is correctly changed. However, the "id_country_chzn" is not changed. The consequence is that although the option is changed, the value displayed for the end user is not changed. Is there a special trigger required ?
The javascript code to update the option in the select is provided below. Could someone help me if I am missing anything ?
town.val('14').trigger('change');

Thanks a lot for your help

A:

When you manually change select value, you need to trigger the changes as well:
$("#id_country").trigger("chosen:updated");

http://harvesthq.github.io/chosen/#change-update-events

