title: How to set values of multiple select using JavaScript
body: <p>To set data of an <code>&lt;input&gt;</code> element using JavaScript, we assign the value and name of that element like this:</p>
  
  <pre><code>var form = document.createElement("form");
  var element = document.createElement("input"); 
  element.value=value;
  element.name=name;
  </code></pre>
  
  <p>In the case of a <code>&lt;select&gt;</code> where the <code>multiple</code> attribute is present, how do I set the value of that select element? For instance, how would I set the value of the <code>myselect</code> element below:</p>
  
  <pre><code>&lt;form method="post" action="/post/" name="myform"&gt;
    &lt;select multiple name="myselect" id="myselect"&gt;
      &lt;option value="1"&gt;option1&lt;/option&gt;
      &lt;option value="2"&gt;option2&lt;/option&gt;
          ...
  </code></pre>
  
  <p>I tried to set the value by doing this <code>myselect.value=[1,2]</code> however it does not work. After selecting <code>option1</code> and <code>option2</code> I expected that it returns <code>[1,2]</code>, but it just returns "1".</p>