Create combo with names inside input value

-1

I have the input with the name collaborator within the while:

while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {

$tabela1 .= '<tr>';

$tabela1 .= '<td>'.$rows_cursos['nome'].'</td>';
$tabela1 .= '<td> <input type="text" name= "Colaborador" value=""</td>';

Within value I want to query the employee table and create a combo with the names of all employees, so they only have to select their name instead of writing.

Within value I wanted to do type what I did in select :

<label for=""><h5><strong>Colaborador</strong></h5></label>
<select name="Colaborador" required>
       <option></option>
        <?php
         $servername = "xxx.xxx.x.xx";
$username = "xxxx";
$password = "xxxxxx";
$dbname = "xxxxxx";

$conn = new mysqli($servername, $username, $password, $dbname);
$conn->set_charset('utf8'); 

         $sql = "SELECT * FROM centrodb.colaboradores WHERE descricaovalencia = 'lar' AND estado = 1 AND Funcao = 'AAD' ORDER BY nome ASC";
         $qr = mysqli_query($conn, $sql);
         while($ln = mysqli_fetch_assoc($qr)){
            echo '<option value="'.$ln['nome'].'">'.$ln['nome'].'</option>';
         }
      ?>        
    </select>

I solved the problem this way:

<td WIDTH="80" align="center"> <select name="Colaborador" id="Colaborador">
   <option></option>
<option value="1">teste</option>
</select></td>';

Instead of using input I used select .

    
asked by anonymous 22.03.2018 / 17:58

2 answers

0
I also do not understand what you are about to do. But have you thought about using Jquery or JavaScript for this action?

Type, when selecting the option of select it triggers an event to fill the input

If so, it is very simple to do.

<select name="produto" id="Produto"  onchange="javascript:associaInput();"*>


function associaInput() {
    //pega o value do select
    var e = document.getElementById("Produto");
    var itemSelecionado = e.options[e.selectedIndex].value;

    //injeta no value do input
    document.getElementByName('produto.Produto').value = itemSelecionado;
}
    
22.03.2018 / 18:09
0

Try this:

<label for=""><h5><strong>Colaborador</strong></h5></label>
<select name="Colaborador" required>
   <option></option>

    <?php

    $servername = "xxx.xxx.x.xx";
    $username = "xxxx";
    $password = "xxxxxx";
    $dbname = "xxxxxx";

    $mysqli = new mysqli($servername, $username, $password, $dbname);


if($th = $mysqli->query("SELECT * FROM centrodb.colaboradores WHERE descricaovalencia = 'lar' AND estado = 1 AND Funcao = 'AAD' ORDER BY nome ASC");
   whiel($row = $th->fetch_assoc()){
    echo '<option value="'.$row['nome'].'">'.$row['nome'].'</option>';

   }

  ?>        
</select>
    
22.03.2018 / 18:09