title: Populating Second Dropdown Based on first dropdown from the database table without using javascript
body: <p>I am trying to create a form for the admin of an e-commerce site and the admin should be able to create a category and add new products. 
  I have two tables in my database from where I want to populate the dropdown list. I want the second dropdown to populate as I select the first drop-down value but I have to do it without the submit button.</p>
  
  <p>This is the code for the form with two drop-downs:- </p>
  
  <pre><code>    &lt;form method="post" action="add_category.php"&gt;
                  &lt;h4&gt;Choose the root level:&lt;/h4&gt;
                  &lt;select name="rootLevel"&gt;
                       &lt;?php
                       $conn = mysqli_connect("localhost","root","","store")
                       or die("Error in Connection on add_category");
  
                       $query = "SELECT * FROM root_category";
                       $result = mysqli_query($conn,$query) or die("Query failed add_category");
                       $id=1;
                       //echo $id;
                       //echo "Hello";
                          while($row = mysqli_fetch_assoc($result)){
                              global $id;
                              //echo "&lt;h1&gt;$id&lt;/h1&gt;";
                              $id = $row['id'];
                              echo "&lt;option name='rootLevel' value=$id&gt;".$row['Name']."&lt;/option&gt;";
                              //echo "&lt;option&gt;$id&lt;/option&gt;";
                              }
  
                          ?&gt;
                  &lt;/select&gt;
                  &lt;br&gt;&lt;br&gt;
                  &lt;h4&gt;Choose the Level 1 Category:&lt;/h4&gt;
  
                  &lt;select name="level1"&gt;
                      &lt;?php
                      global $id;
                      //echo "&lt;option&gt;".$_POST['rootLevel']."&lt;/option&gt;";
                      $query_level1 = "Select * from level1_category Where P_id = $id";
                      $result1 = mysqli_query($conn,$query_level1) or die("Query failed level 1");
                      while($row = mysqli_fetch_assoc($result1)){
                          $id1 = $row['P_id'];
                          echo "&lt;option name='level1' value=$id1&gt;".$row['Name']."&lt;/option&gt;";
                      }
                      ?&gt;
                  &lt;/select&gt;
  </code></pre>
  
  <p>I have successfully populated the first drop-down and now I want to fetch the $id in 'resultValue' without the submit button.</p>