Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

jquery-select2

how to change select2 value programmatically

September 20, 2023 by Tarik

$(‘#select_id’).val(‘val’).trigger(‘change’); is the right way, see here

Categories jquery-select2 Tags jquery-select2, jquery-select2-4 Leave a comment

Select2 doesn’t show selected value

July 22, 2023 by Tarik

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

Categories jquery-select2 Tags jquery-select2 Leave a comment

How can I set the initial value of Select2 when using AJAX?

December 29, 2022 by Tarik

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

Categories jquery-select2 Tags jquery-select2, jquery-select2-4 Leave a comment

Select2 dropdown but allow new values by user?

December 9, 2022 by Tarik

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

Categories jquery-select2 Tags jquery-select2 Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa