title: How can I set the default value for an HTML <select> element with JavaScript?
body: <p>How to set the 'selected' (default) value for an HTML <code>&lt;select&gt;</code> element with JavaScript. Aka. currently option0 is 'selected', how to run a script to change it to display the value i want?</p>
  
  <p><em>this for example because that value is previously saved in a database, and i only want it updated if the user actually specifies to do so. But if i don't specify the value (by re-selecting the previous option), saving the 'edit' will overwrite the previous value with the 'default selected' value the <code>&lt;select&gt;</code> is loaded with.</em></p>
  
  <pre><code>&lt;select id="selector" name="selector"&gt;
    &lt;option id="option0" value="0" selected=true &gt;default &lt;/option&gt;
    &lt;option id="option1" value="1"&gt;option 1 &lt;/option&gt;
    &lt;option id="option1" value="2"&gt;option 2 &lt;/option&gt;
    &lt;option id="option1" value="3"&gt;option 3 &lt;/option&gt;
    &lt;option id="option1" value="4"&gt;option 4 &lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p><strong>NOTE</strong>: <em>Because i lack reputation to add my answer (below) to the general thread on this topic, here the solution i got to using javascript, to set an option to be the option displayed/selected in the selector. This can also be a &lt;%= value %> from a database.</em></p>