title: Fill value in second dropdown on changing of first from database
body: <p>hey guys i am new to php and i have two select tag and i want to fill second select tag from database based on first please help me out as i have been facing the issue from last three days . i have written the code from javascript php and the name of the second page is api.php.</p>
  
  <pre><code> &lt;html&gt;
   &lt;head&gt;
   &lt;script src="js/jquery.min.js" &gt;&lt;/script&gt;
   &lt;/head&gt;
   &lt;body&gt;
       &lt;form method="post" class="form-horizontal" &gt;
        &lt;label class="col-lg-3 control-label"&gt;Category&lt;/label&gt;
        &lt;select id="category" class="form-control" name="Category"&gt;
           &lt;option&gt;Select Category&lt;/option&gt;
          &lt;?php
              $con=mysqli_connect("localhost","root","","keep_shopping");
              $select="select * from tbl_category";
              $result=mysqli_query($con,$select);
               while($row=$result-&gt;fetch_assoc()){
                $CategoryName=$row['CategoryName'];   
                $CategoryId=$row['CategoryId'];   
              ?&gt;
             &lt;option  value="&lt;?php echo  $CategoryId;?&gt;"&gt;&lt;?php echo $CategoryName;?&gt;&lt;/option&gt; 
   &lt;?php
   }
   ?&gt;                                        
  &lt;/select&gt;
            &lt;br /&gt;
            &lt;br /&gt;
            &lt;br /&gt;
              &lt;label class="col-lg-3 control-label"&gt;Brand&lt;/label&gt;
              &lt;select id="brand" class="form-control" name="Brand"&gt;
                 &lt;option&gt;Select a Brand&lt;/option&gt;
              &lt;script&gt;
                  $(document).ready(function(){
                      alert('Change Happened');
                      $('#category').change(function(){
                      var CategoryId=$(this).val();
                      $.ajax({
                           'type':'get',
                           'url':'api.php',
                            'data':{'CategoryId':CategoryId,'btn':1},
                             'success':function(response){
                          document.getElementById("brand").innerHTML=response;
  }
  });
  });
  });
      &lt;/script&gt;
      &lt;/select&gt;
      &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  
  second page name is api.php
  
  &lt;?php
  if(isset($_GET['btn'])){
  $CategoryId=$_POST['CategoryId'];
  $con=mysqli_connect("localhost","root","","keep_shopping");
  $select=mysqli_query($con,"select * from tbl_brand where 
  CategoryID='$CategoryId'");
  $states='&lt;option&gt;-SELECT CITY-&lt;/option&gt;';
  while($row=$select-&gt;fetch_assoc()){
  $states.='&lt;option  
  value="'.$row["BrandID"].'"&gt;'.$row["BrandName"].'&lt;/option&gt;';     
  }
  echo $states;
  }
  ?&gt;
  </code></pre>