title: Jquery chosen set selected values from javascript
body: <p>I am using jquery chosen and I want to set selected values from javascript</p>
  
  <p><strong>Javascript/Jquery</strong></p>
  
  <pre><code>$(document).ready(function() {
    var selectedUserRole = document.getElementById('SelectedUserRole').value;
    var str_array = selectedUserRole.split(',');
  
    for (var i = 0; i &lt; str_array.length; i++) {
      // Trim the excess whitespace.
      str_array[i] = str_array[i].replace(/^\s*/, "").replace(/\s*$/, "");
      // Add additional code here, such as:
  
      $("UserRole").prop('selectedValue', str_array[i]); // Here not working
    }
  });
  </code></pre>
  
  <p><strong>Html:</strong></p>
  
  <pre><code> @Html.DropDownList("UserRole", null, new { id = "UserRole", @class = "chosen-select", @multiple = "multiple", @placeholder = "Lütfen Rol Seçiniz", @style = "width: 250px;" })
  </code></pre>
  
  <p>str_array has values below</p>
  
  <p>[5, 1, 7]</p>
  
  <p>I want to <strong>set 5 value selected, 1 value selected 7 value selected</strong> </p>
  
  <p>When I tried below </p>
  
  <pre><code>$("UserRole").prop('selectedValue', str_array[i]);
  </code></pre>
  
  <p>it is not working for me. </p>