I'm trying to change the currently selected option in a select with the Chosen plugin.
The documentation covers updating the list, and triggering an event when an option is selected, but nothing (that I can see) on externally changing the currently selected value.
I have made a jsFiddle to demonstrate the code and my attempted ways of changing the selection:
$('button').click(function() {
$('select').val(2);
$('select').chosen().val(2);
$('select').chosen().select(2);
});
My answer is late, but i want to add some information that is missed in all above answers.
1) If you want to select single value in chosen select.
2) If you are using multiple chosen select, then may you need to set multiple values at single time.
Information gathered from following links:
1) Chosen Docs
2) Chosen Github Discussion
Sometimes you have to remove the current options in order to manipulate the selected options.
Here is an example how to set options:
JSFiddle (including howto append options): https://jsfiddle.net/tbaf0r38/30/
From the "Updating Chosen Dynamically" section in the docs: You need to trigger the 'chosen:updated' event on the field
NOTE: versions prior to 1.0 used the following: