title: How to auto populate other field based on the selection from dropdown
body: <p>I have created this page to fetch data from my database based on the selection of drop down which is also derived from the database. Please help me in this regard as I am stuck with no luck. Here is my code:</p>
  
  <pre><code>&lt;head&gt;
  &lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type" /&gt;
  &lt;title&gt;Untitled 1&lt;/title&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;?php
  $connection = mysqli_connect("localhost", "root", "rajat123", "callboard");
  $data = "select * from customermaster";
  $query = mysqli_query($connection, $data);
  ?&gt;
  &lt;form name="sysadd" id="form1" method="post" action="system_reg2.php"&gt;
  Customer Name:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;select name="custname" id="custname" onchange="updatetext()"&gt;
  &lt;?php
      while ($row = $query-&gt;fetch_assoc()) {
          echo "&lt;option value=\"{$row['custname']}\"&gt;";
          echo $row['custname'];
          echo "&lt;/option&gt;";
      }
  ?&gt;
  &lt;/select&gt;&lt;br /&gt;&lt;br /&gt;
  &lt;input type="text" name="type" id="type" /&gt;
  &lt;input type="text" name="sl_no" id="sl_no" /&gt;
  &lt;input type="text" name="config" id="service" /&gt;
  &lt;input type="text" name="date" id="date" /&gt;
  
  &lt;/form&gt;
  &lt;script type="text/javascript"&gt;
  
          function updateText() {
              var custname2 = document.getElementById("custname").value;
              &lt;?php $data2 = mysqli_query($connection, "SELECT * FROM customermaster WHERE custname = 'custname2'") ; ?&gt; 
              &lt;?php $row = mysqli_fetch_array($data2); ?&gt;
            document.getElementById("type").value = &lt;?php echo $row['type'] ?&gt;;
            document.form1.sl_no.value = &lt;?php echo $row['sl_no'] ?&gt;;
            document.form1.config.value = &lt;?php echo $row['config'] ?&gt;;
            document.form1.date.value = &lt;?php echo $row['date'] ?&gt;;
  
      }
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>