Selecting a Select2 Option Using Javascript

Copying the same template as
to
:
Solution 2:
This code is for getting selected country value in dropdown with country flag in it using ip address of the server and by using google plugins ..
Solution:
I know it’s been a while, but there is a workaround for this.
Turns out that if you add an empty
to the select tag, and add a placeholder, the issue is fixed.
Solution:
You can use
this will give you option tag html then using this you can get the
value and compare it with all options attr if not same disabled that option.


Solution:

By examining the origin of the fiddle, it becomes evident that the select2 library resource versions vary.

Check out this link for Version 3.5.2: http://jsfiddle.net/tw57m8bx/1/



Check out the 4.0.5 version at http://jsfiddle.net/vipTelnet/m7vx0nuc/2/.



An update has been made to ensure compatibility with version 4.0.5.

You can access the functional fiddle via this link: http://jsfiddle.net/m7vx0nuc/3/.

To bind data, you should include a data attribute to

select2()

. Additionally, make sure to add an empty

option

tag in the HTML to avoid selecting the first element by default.

$('#select').select2({
   minimumInputLength: 0,
   data:lastOptions
});

Frequently Asked Questions

Posted in Uncategorized