title: How to preselect a <select> list item in using JavaScript
body: <p>I have this markup and javascript. I cannot get the "T" option (for example) to preselect on page load. Is it possible?</p>
  
  <pre><code>    &lt;select id="serviceType" name="serviceType" class="form-control"&gt;
        &lt;option value="S"&gt;S&lt;/option&gt;
        &lt;option value="T"&gt;T&lt;/option&gt;
        &lt;option value="X"&gt;X&lt;/option&gt;
      &lt;/select&gt;
      &lt;script&gt;
          //document.getElementById("serviceType").selectedIndex = "T"; // did not work
        var e = document.getElementById("serviceType");
        e.options[e.selectedIndex].value = "T"; // does not work
      &lt;/script&gt;
  </code></pre>
  
  <p>Note: "T" is dynamic at page build time in PHP from a DB call. So my script actually looks like this:
  <code>= "&lt;? echo $_POST['serviceType']; ?&gt;"</code></p>