Answers.Body: <p>you can also do it this way by defining javascript array.</p>
  
  <pre><code>var Values = new Array();
  Values.push("value1");
  Values.push("value2");
  Values.push("value3");
  
  $("#my_select2").val(Values).trigger('change');
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-27T06:45:07.530Z
Answers.LastActivityDate: 2017-12-27T06:45:07.530Z
Answers.UserDisplayName: Saurabh Solanki
Answers.Body: <p>Ok, I found the way. It's just passing an array of option values to 'val' argument:</p>
  
  <pre><code>$('#my_select2').select2('val', ["value1", "value2", "value3"]);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-07T16:20:14.370Z
Answers.Text: an anonymous users just posted this as an alternative solution:
  
  
  var data = {
      id: 1,
      text: 'Barn owl'
  };
  var newOption = new Option(data.text, data.id, false, false);
  $('#mySelect2').append(newOption).trigger('change');
  
  
  this solution is referenced from https://select2.org/programmatic-control/add-select-clear-items#creating-new-options-in-the-dropdown
Answers.UserDisplayName: luciano_s
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-17T14:28:12.007Z
Answers.LastActivityDate: 2017-05-17T14:28:12.007Z
Answers.UserDisplayName: luciano_s
Body: <p>I want to select multiple options in a select2 multivalue control, when clicking a button.
  This is useful specially for searches where the user needs to select many option to one of the filters</p>
  
  <p>any idea how to achieve it..? 
  I found how to select an option in select2 single option dropdown, but not in a multiselect control for several options at the same time</p>
  
Tags: <jquery><select2>
Title: How to select multiple values in select2 control by jquery?
ThreadText: # How to select multiple values in select2 control by jquery?
  
  (Asked by: username_0 on 2017-05-16)
  
  I want to select multiple options in a select2 multivalue control, when clicking a button.
  This is useful specially for searches where the user needs to select many option to one of the filters
  
  any idea how to achieve it..?
  I found how to select an option in select2 single option dropdown, but not in a multiselect control for several options at the same time
  
  **Tags:** jquery, select2
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2017-05-17. Score: 6 | Accepted answer
  
  Ok, I found the way. It's just passing an array of option values to 'val' argument:
  $('#my_select2').select2('val', ["value1", "value2", "value3"]);
  
  > **Comments:**
  > **username_0**: an anonymous users just posted this as an alternative solution:   var data = {     id: 1,     text: 'Barn owl' }; var newOption = new Option(data.text, data.id, false, false); $('#mySelect2').append(newOption).trigger('change');   this solution is referenced from https://select2.org/programmatic-control/add-select-clear-items#creating-new-options-in-the-dropdown  
  
  ---
  
  ### Answer by username_1 on 2017-12-27. Score: 1
  
  you can also do it this way by defining javascript array.
  var Values = new Array();
  Values.push("value1");
  Values.push("value2");
  Values.push("value3");
  
  $("#my_select2").val(Values).trigger('change');
  
  
  ---
  
  