title: How to make an option selected in dynamic dropdown list
body: <p>I have a dynamic dropdown list of states. When I am selecting an option it is reloading another page, where I am displaying district belonging to that state. Now I want to do here after reloading the page of district I want to make the selected state display there in dropdown. I am unable to do that becasue it is dynamic </p>
  
  <p>District page Code.</p>
  
  <pre><code>&lt;option value=""&gt;&lt;?php echo $state; ?&gt;&lt;/option&gt;
                          &lt;?php
                          if(!empty($stateNew)){
                              foreach($stateNew as $row){ 
                                  echo '&lt;option value='.$row['id'].'&gt;'.$row['state_name'].'&lt;/option&gt;';
                              }
                          }else{
                              echo '&lt;option value=""&gt;District not available&lt;/option&gt;';
                          }
                          ?&gt;  
                          &lt;/select&gt;
  
                          &lt;select id="state" class="bankSelect" name="state"&gt;
                          &lt;option value=""&gt;Select District&lt;/option&gt;
                          &lt;?php
                          if(!empty($district)){
                              foreach($district as $row){ 
                                  echo '&lt;option value='.$row['id'].'&gt;'.$row['district_name'].'&lt;/option&gt;';
                              }
                          }else{
                              echo '&lt;option value=""&gt;District not available&lt;/option&gt;';
                          }
                          ?&gt;                                  
                          &lt;/select&gt;
  
                          &lt;select id="city" class="bankSelect"&gt;
                                  &lt;option value=""&gt;Select district first&lt;/option&gt;                                 
                          &lt;/select&gt;
  </code></pre>
  
  <p>State page Code:</p>
  
  <pre><code> &lt;option value=""&gt;Select State&lt;/option&gt;
                          &lt;?php
                          if(!empty($state)){
                              foreach($state as $row){ 
                                  echo '&lt;option value='.$row['id'].'&gt;'.$row['state_name'].'&lt;/option&gt;';
                              }
                          }else{
                              echo '&lt;option value=""&gt;State not available&lt;/option&gt;';
                          }
                          ?&gt;
                          &lt;/select&gt;
  
                          &lt;select id="state" class="bankSelect"&gt;
                                  &lt;option value=""&gt;Select state first&lt;/option&gt;                                    
                          &lt;/select&gt;
  
                          &lt;select id="city" class="bankSelect"&gt;
                                  &lt;option value=""&gt;Select District first&lt;/option&gt;                                 
                          &lt;/select&gt;
  </code></pre>
  
  <p>All the values I am fetching from the database.</p>