Create combo with names within input value

Asked

Viewed 177 times

-1

have input with name contributor inside 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 the value I want to make a query of the employees' table and create a combo with the names of all employees, so they only have to select their name instead of writing.

Within the value I wanted to do like this 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 a input I used the select.

  • Man, I don’t quite understand what you want to do?

  • You want to use the $rows_corsos['name'] field to make a new query?

  • I already edited the question and showed what I wanted to do inside the value, like what I do inside the select

  • 1

    What you want is not possible, you can simply replace your input text with the input select, what would make it easier would be wanted your input select in a variable before mounting the table, then in place in the input text.

  • Take a look there

  • @marcelogribeiro, can put an example?

Show 1 more comment

2 answers

0

I also don’t understand what you intended to do. But you’ve thought about using Jquery or Javascript for this action?

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

If so, it’s 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;
}
  • Is that??? if not, be a little more specific

  • Inside the input I want to make a query to the database table to appear soon all the names that exist within the table, so the user does not need to be writing his name

  • Use the input with autocomplete . As he is typing his name will appear in the search. Type Google. You escre and he will suggest.

  • You know Jquery? is very simple to implement. It will call the event every letter you type. Then it returns the list of your query. Give a search in some examples. anything put there that I help you.

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>
  • And then as I call this select within input value?

  • @Beginner take a look at this: https://answall.com/questions/44174/como-pega-o-valor-dinamicamente-de-um-select

Browser other questions tagged

You are not signed in. Login or sign up in order to post.