title: How to set a default selection and value in dropdownlist with data from database?
body: <p>I have a dropdownlist with data loaded from MySQL database. The data.list was the list of data produced by a SQL query in node.js. Each record has a ID and a name. I want to set a default selection where the selected name is "John". The code below generates a dropdown where all options are selected instead of the option with name "John". Is there any way that I can achieve this by javascript? Thanks. </p>
  
  <p>HTML Code with javascript:</p>
  
  <pre><code>        &lt;select id="mySelect" name="mySel" size =20 multiple&gt;
                  &lt;% if(data.list) { %&gt;
                      &lt;% data.list.forEach(function (row) { %&gt;
                          &lt;option value="&lt;%= row.ID %&gt;" &lt;% row.name %&gt; === "John" ? selected = true : false&gt;&lt;%= row.name %&gt;&lt;/option&gt;
                      &lt;% }) %&gt;
                  &lt;% } %&gt;  
          &lt;/select&gt;
  </code></pre>