title: Input value based on Select and SQL result?
body: <p>Ok, I have a SQL table "departamentos"</p>
  
  <p><img src="https://i.stack.imgur.com/8EcPP.jpg" alt="IMAGE OF TABLE"></p>
  
  <p>And I have form like this:</p>
  
  <pre><code>&lt;form class="form-signin" action="controlador/controlador.php?accion=GuardarCompromiso" method="post" id="agregarCompromiso" style="display:none;" role="form"&gt;
  
          &lt;select class="form-control" id="departamento" name="departamento" required&gt;
                    &lt;option selected disabled value=""&gt;Departamento&lt;/option&gt;
                            &lt;option value="Distribucion"&gt;Distribución&lt;/option&gt;
                            &lt;option value="Pycon"&gt;Pycon&lt;/option&gt;
                            &lt;option value="Planeacion"&gt;Planeación&lt;/option&gt;
                            &lt;option value="Comercial"&gt;Comercial&lt;/option&gt;
                            &lt;option value="Administracion"&gt;Administración&lt;/option&gt;
                            &lt;option value="Personal"&gt;Personal&lt;/option&gt;
                            &lt;option value="Ingenieria de Servicio al Cliente"&gt;Ingeniería de Servicio al Cliente&lt;/option&gt;
                            &lt;option value="Atencion a Clientes"&gt;Atención a Clientes&lt;/option&gt;
                            &lt;option value="Sistema Integral de Gestion"&gt;Sistema Integral de Gestión&lt;/option&gt;
                            &lt;option value="CFEctiva"&gt;CFEctiva&lt;/option&gt;
                            &lt;option value="Juridico"&gt;Jurídico&lt;/option&gt;
                            &lt;option value="Agencia Ures"&gt;Agencia Ures&lt;/option&gt;
                            &lt;option value="Agencia Miguel Aleman"&gt;Agencia Miguel Alemán&lt;/option&gt;
                            &lt;option value="Agencia Sahuaripa"&gt;Agencia Sahuaripa&lt;/option&gt;
          &lt;/select&gt;
  
          &lt;input name="destinatario" id="destinatario" type="text" class="form-control" placeholder="Destinatario" required /&gt;
          &lt;input name="correo" id="correo" type="text" class="form-control" placeholder="Correo" required /&gt;
  
          &lt;div class="btn_login"&gt;
          &lt;input class="btn btn-lg btn-primary btn-block" type="submit" value="Agregar Compromiso" /&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>Now, I need to dinamically change values of input 'destinatario' and input 'correo' depending on selected option. I know this can be done with Javascript or Jquery or something like, but I need this to be done with a MySQL result, because fields 'encargado' and 'correo' in MySQL table have often changes, so I wont be updating Javascript code every time.</p>
  
  <p>In other words, I need an event on the select input, like onchange connect to db and send a query like</p>
  
  <pre><code>select 'encargado' from departamentos where departamento=SELECTEDOPTION;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>select 'correo' from departamentos where departamento=SELECTEDOPTION;
  </code></pre>
  
  <p>and bring those values back to input 'destinatario' and input 'correo' respectivey.</p>