title: JavaScript retrieve data from DB
body: <p>In my database I have table <code>Person (id, name, last_name, phone_number)</code>. I do something like this:</p>
  
  <pre><code>$queryPerson = mysqli_query($con, 'SELECT * FROM Person');
  while ($person = mysqli_fetch_array($queryPerson)) {
                 echo '&lt;option value="'.$person["id"].'"&gt;'.$person["name"].' '.$person["last_name"].'&lt;/option&gt;'; 
  }
  </code></pre>
  
  <p>I want to use javascipt function to copy selected value from the select to textboxes:</p>
  
  <pre><code>function copyPerson(data) {
      document.getElementById["name"].value = data.value;
  }
  </code></pre>
  
  <p>...but instead of their id I want their names and last names and phone numbers to be displayed in textboxes.  Now I came up with this idea to read the value from an option, send query to DB <code>SELECT * FROM Person WHERE id = ID_FROM_SELECT</code> and then recieve the data I want to recieve. I'm not sure if it's a good idea though.</p>
  
  <p>In before: yes, I need to have <code>$person["id"]</code> as a value of an option.</p>
  
  <p>My question is: sending the query to DB is a good idea - if yes, how can I send a value from javascript to MySQL, if no - what is a better solution?
  <hr>
  EDIT: Apart from @Thanos Tourikas answer, I found this link to be helpful: <a href="http://www.w3schools.com/php/php_ajax_database.asp" rel="nofollow">http://www.w3schools.com/php/php_ajax_database.asp</a> </p>