title: Loop through a data array variable and select items from multi-select dropdown
body: <p>Created a multi-select dropdown, when I click on any of the options I have a input field which stores the values in a textbox. When the page reloads- I want to reselect the values in the multi-select drop down. The text box keeps its values so i was hoping to loop through this if i put it in an array.</p>
  
  <p>E.g. Text contains: "cheese,mozarella"</p>
  
  <p>It is important to only check the items that have the value in the textbox</p>
  
  <p>Jquery:</p>
  
  <pre><code>document.getElementById("txt1").value = "cheese,mozarella";
  var data =  document.getElementById("txt1").value;
  var dataarray = data.split(","); //splits values (,)
  
  console.log(dataarray);
  
  var i;
  for (i = 0; i &lt; dataarray.length; i++) {       
  }
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code> &lt;input type="text" runat="server" id="txt1" visible="true" value="0" /&gt; 
  
  &lt;div class="container"&gt;
      &lt;select id="basic" multiple="multiple"&gt;
          &lt;option value="cheese"&gt;Cheese&lt;/option&gt;
          &lt;option value="tomatoes"&gt;Tomatoes&lt;/option&gt;
          &lt;option value="mozarella"&gt;Mozzarella&lt;/option&gt;
          &lt;option value="mushrooms"&gt;Mushrooms&lt;/option&gt;
          &lt;option value="pepperoni"&gt;Pepperoni&lt;/option&gt;
          &lt;option value="onions"&gt;Onions&lt;/option&gt;
      &lt;/select&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I have a codeply to demonstrate: <a href="https://www.codeply.com/go/mCcxCM0vHs" rel="nofollow noreferrer">https://www.codeply.com/go/mCcxCM0vHs</a></p>
  
  <p>My aim is to get some jquery code to loop through a dataarray variable and check the box if the value exists and tick it.</p>