title: OnClick button Get from database and display on a input field live
body: <p>I am trying to input some text on a input field and on <code>click</code> the button it should display data from mysql on another input field name <code>autofiller</code>. </p>
  
  <pre><code>$(function () {
    $('#button').on('click', function () {
      var text = $('#fromInput');
      $.ajax({
        url:"serv.php",
        method: "GET",
        data: {
          "id": text
        },
        success: function(data) {
          var name=JSON.parse(data);
          document.getElementsByClassName("autofiller").value=name.name;
        }
      });
    });
  });
  </code></pre>
  
  <p>HTML form</p>
  
  <pre><code>&lt;form id="sampleForm"&gt;
   &lt;input type="text" id="fromInput" /&gt;
   &lt;input type="text" class="autofiller"/&gt;
  
   &lt;input type="button" value="button" id="button"&gt;
  </code></pre>
  
  <p></p>
  
  <p>This is my back-end php script--></p>
  
  <pre><code>&lt;?php
      $link=mysqli_connect("localhost","root","","employee");
  
  
  
      $data=$_GET["id"];
  
    $result = mysqli_query($link,"SELECT * FROM user where userid='$data'");
  
    header('Content-type:application/json');
    exit(json_encode($result));
   ?&gt;
  </code></pre>