title: How to make an option selected based on the page (URL)?
body: <p>i have created a dropdown where i have a dropdown of multiple records of users. When i select first option, the page redirect to the link which open details page of user. Now, i want to set the selected user inside select option field. here is my code</p>
  <pre><code>&lt;select class=&quot;user&quot;&gt;
  
  &lt;?php foreach($user as $key =&gt; $value): ?&gt;
  
      &lt;optgroup label=  &lt;?php echo $key; ?&gt; &gt;
  
          &lt;?php foreach($value as $row): ?&gt;
              &lt;option value=&quot;&lt;?php echo $row['id'] ?&gt;&quot; class=&quot;key-select-option&quot;&gt;
                  &lt;?php echo $row['name'] .' &amp; '. $row['roll_number'] ?&gt;
              &lt;/option&gt;
          &lt;?php endforeach; ?&gt;
  
      &lt;/optgroup&gt;
  
  &lt;?php endforeach; ?&gt;
  
  &lt;/select&gt;
  
  
  $('.user').on('change', function() {
          var userId = $(this).val();
  
          var url = 'https://localhost/user/' + userId;
          window.location.href = url;
  });
  </code></pre>
  <p>This code redirect me to another page but how to make this selected inside your dropdown?</p>