title: Getting selected option value without postback/submit PHP
body: <p>I'm trying to get select options from database that works for now, but I can't  get the selected value without submitting the <code>&lt;form&gt;</code> </p>
  
  <pre><code>&lt;label for="NomEns"&gt;Choisir un enseignant: &lt;/label&gt;
  &lt;select name="dd1" id="combo" class="form-control"&gt;
      &lt;option value="" &lt;?php if(!isset($_POST['NomEns']) || (isset($_POST['NomEns']) &amp;&amp; empty($_POST['NomEns']))) { ?&gt;selected&lt;?php } ?&gt;&gt;--Select--&lt;/option&gt;
  &lt;?php while($row = $result-&gt;fetch_assoc()) { ?&gt;
      &lt;option value="&lt;?php echo $row['NomEns']; ?&gt;" &lt;?php if(isset($_POST['NomEns']) &amp;&amp; $_POST['NomEns'] == $row['NomEns']) { ?&gt;selected&lt;?php } ?&gt;&gt;&lt;?php echo $row['NomEns']; ?&gt;&lt;/option&gt;
  &lt;?php } ?&gt;
  &lt;/select&gt;
  </code></pre>