select multiple dropdown by using select2 library javascript

Solutions on MaxInterview for select multiple dropdown by using select2 library javascript by the best coders in the world

showing results for - "select multiple dropdown by using select2 library javascript"
Kirsten
17 Apr 2019
1######## In your HTML:
2<select class="js-example-basic-multiple" name="states[]" multiple="multiple">
3  <option value="AL">Alabama</option>
4    ...
5  <option value="WY">Wyoming</option>
6</select>
7
8####### In your Javascript (external .js resource or <script> tag):
9$(document).ready(function() {
10    $('.js-example-basic-multiple').select2();
11});
12
13######### Get Selected values
14$('.js-example-basic-multiple').select2('val')
15
16######## Pre select values on page loads
17 $('.js-example-basic-multiple').val(['AL', 'WY']).trigger('change');
Adem
22 Sep 2019
1<html>
2  <head>
3    <title>Using Select2</title>
4    <!-- Bootstrap CSS -->
5    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
6    <!-- Select2 CSS -->
7    <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
8  </head>
9  <body>
10    <div class="jumbotron">
11      <div class="container bg-danger">
12        <div class="col-md-6">
13          <label>Single Select2</label>
14          <select id="single" class="js-states form-control">
15            <option>Java</option>
16            <option>Javascript</option>
17            <option>PHP</option>
18            <option>Visual Basic</option>
19          </select>
20        </div>
21        <div class="col-md-6">
22          <label>Multiple Select2</label>
23          <select id="multiple" class="js-states form-control" multiple>
24            <option>Java</option>
25            <option>Javascript</option>
26            <option>PHP</option>
27            <option>Visual Basic</option>
28          </select>
29        </div>
30      </div>
31    </div>
32    <!-- jQuery -->
33    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
34    <!-- Select2 -->
35    <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
36    <script>
37      $("#single").select2({
38          placeholder: "Select a programming language",
39          allowClear: true
40      });
41      $("#multiple").select2({
42          placeholder: "Select a programming language",
43          allowClear: true,
44          maximumSelectionLength: 2
45      });
46    </script>
47  </body>
48</html>
queries leading to this page
how to use select 2 dropdownselect2 js multiple select allselect2 single selectselect2 selectionselect2 multiple select problemmultil select 2multi selectselect2 multiple exampleselect2 selectselect2 multiple checkboxmulti select box select2select2 multiple select with searchget select2 multiple dataselect 2 multiselectworking with multiple dropdown select javascriptselect2 multi select with jquerselect2 multi line optionmultiselect in select2select2 single selection for selection templateselect2 multi value select boxesselect2 single selection resulthow to use select2 multipleselect2 multi select cssjquery select2 multi selectmulti select ajax select2select 2 multi selectselect2 multiple selection dropdownselect2 multi select selected valueselect2 multiple select designselect2 multiple select option by idselect2 multiple jsselect2 multi select select allselect2 multiple seleall select with select2multiple select dropdown jqueryselect2 select valueselect2 multiple select orderselect i multi selectselect2 select multiple values in the dropdownselect2 dropdown 2select2 multiple select dropdown railshow to select in select2get selected option select2 multipleselect2 dropdown single selectselect2 one more options select allmulti select select2 ajaxhow to get multitiple select id in select2select select2multiple select dropdownmulti select 2 exampleselect2 select optionselect2 js multiple select examplemulti select select boxselect2 multi selectselect multi selectsearching in select2 multiple selectselect2 multi select checkboxmulti select dropdown with checkbox select2select2 multipleselectjs select multiple in dropdownjquery select2 multiple selectmultiple select2 dropdownselection select2javascript select2 multi selectselect2 selected optionsmultiple select2 select2 multi select filter optionsselect2 dropdown multiselectselect2 multiple selectedselect2 multiselction one option selectedselect2 multiple select with tag inputselect2 multiple select alldrop down came select select2 multiple selectselect multiselect2 multiselect with checkboxselect2 multiselect to single selectselect2 multi select with checkboxjavascript multiselect dropdownmultilevel select with select 2select2 examplemulti select in select2select2 creating two selectsget select2 selection select2 select multiple itemsselect2 selected optionselect2 multi select css exampleselect2 selectedselect2 with selected valueselect2 multiple select dropdown rails select tagtwo html select with select2multiple selection select2select2 control 27select multi selectmultiple select2 dropdown in one pagemultiselect in select2 railsselect2 in multi sectsingle select select2select2 multiple tagsmultiple selection dropdown select2select2 multi select set valueselect2 on selectselect2 select multiple options select allselect2 option selected multipleselect2 22selectselect2 multiple selectmultiselect select2multi select comboselect2 multiple select with checkboxselect all in multiselect select2select2 multipleselect2 multiple selectonmulti select in selectselect2 withselect2 multi select programmaticallyselected in select2how to select multiple option in select2 using jqueryhow to select the selected option with select2select2 multi value select boxes exampleselect2 with select all option multiple select select2select2 value multiplemulti select select2 dropdownselect2 singleselect2 multiselect multiple dropdown by using select2 library javascriptselect2 with multiple select jquery multiple select dropdownselect2 two selectsselect2 multiple select boxesmultiple select dropdown select2select2 select with javascriptselect2 multiple select jsselect2 multiple select with taguse ajax in multiple select dropdown multiple selectmulti select boxes selected attribute in select2multiple select2 valueselect tag for multiple section dropdown with select2get selection from select2select2 demo multiple optionsselect2 two select elementsselect value in select2 select2 28 29select multiple option in dropdown using jqueryselect2 on select selectedin select2 multiple select2 multiple selectionselect2 multiple select dropdownselect2 select dropdownmultiple item select in select2 dropdownset multi select value to select2how to multi select option in select2 using jqueryselect 2 multiple selectmulti select listselect of the multi selectmulti select dropdown jqueryselect2 2 selectselect2 multiple select all examplemulti select select2select multi value on click select2select2 multi select one option selectedmultiple select2 htmlselect2 multiselectselect multiple dropdown by using select2 library javascript