title: I want to display a name based on the id select in dynamic dropdown list
body: <p>I want to display name in textbox based on the selected id. This id to be dynamically displayed in dropdown list, so while select it the name will displayed from the db table. </p>
  
  <p>HTML code:</p>
  
  <pre><code>   &lt;form name="insert" action="" method="post"&gt;
      &lt;table width="100%" height="117"  border="0"&gt;
      &lt;tr&gt;
      &lt;th width="27%" height="63" scope="row"&gt;ID :&lt;/th&gt;
      &lt;td width="73%"&gt;&lt;select onChange="getdistrict(this.value);"  name="state" id="state" class="form-control" &gt;
      &lt;option value=""&gt;Select Id&lt;/option&gt;
      &lt;?php $query =mysqli_query($con,"SELECT * FROM patreg");
      while($row=mysqli_fetch_array($query))
      { ?&gt;
     &lt;option value="&lt;?php echo $row['id'];?&gt;"&gt;&lt;?php echo $row['name'];?&gt;&lt;/option&gt;
      &lt;?php
      }
      ?&gt;
      &lt;/select&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
      &lt;th scope="row"&gt;Name :&lt;/th&gt;
      &lt;td&gt;
      &lt;input type="text" id="district-list" class="form-control" value="&lt;?php echo $row["name"]; ?&gt;"&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
      &lt;/table&gt;
       &lt;/form&gt; 
  
  &lt;?php
         require_once("config.php");
         if(!empty($_POST["name"])) 
         {
         $query =mysqli_query($con,"SELECT `name` FROM `patreg` WHERE `id` = '$id'");
         ?&gt;
      &lt;option value=""&gt;Select District&lt;/option&gt;
      &lt;?php
         while($row=mysqli_fetch_array($query))  
         {
         ?&gt;
      &lt;?php echo $row["name"]; ?&gt;
      &lt;?php
         }
         }
         ?&gt;
  </code></pre>
  
  <p>ID  =  100001 while selected name =  abcdef to be displayed automatically</p>
  
  <pre><code>&lt;script&gt;
     function getdistrict(val) {
      $.ajax({
      type: "POST",
      url: "get_district.php",
      data:'id='+val,
      success: function(data){
          $("#district-list").html(data);
      }
      });
     }
     function selectCountry(val) {
     $("#search-box").val(val);
     $("#suggesstion-box").hide();
     }
  &lt;/script&gt;
  </code></pre>