how to change select2 value programmatically
$(‘#select_id’).val(‘val’).trigger(‘change’); is the right way, see here
$(‘#select_id’).val(‘val’).trigger(‘change’); is the right way, see here
You need to use the initSelection option to set the initial value. If you are using a pre-defined select element to create the select2, you can use the following method $(‘select’).select2().select2(‘val’,’3′) Demo: Fiddle
You are doing most things correctly, it looks like the only problem you are hitting is that you are not triggering the change method after you are setting the new value. Without a change event, Select2 cannot know that the underlying value has changed so it will only display the placeholder. Changing your last part … Read more
The excellent answer provided by @fmpwizard works for Select2 3.5.2 and below, but it will not work in 4.0.0. Since very early on (but perhaps not as early as this question), Select2 has supported “tagging”: where users can add in their own value if you allow them to. This can be enabled through the tags … Read more