receive two values autocomplete and pass to input tipe = 'hidden'

1

How do I pass a 'ID - valor' value of a autocomplete jquey and show only the 'valor' in the input field and pass 'ID' to another input type hidden .

  

PHP

if (isset($_GET['term'])){
$return_arr = array();

try {
    $conn = new PDO("mysql:host=".DB_SERVER.";dbname=".DB_NAME, DB_USER, DB_PASSWORD);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $stmt = $conn->prepare("SELECT id,nome FROM produtos WHERE nome LIKE :term ");
    $stmt->execute(array('term' => '%'.$_GET['term'].'%'));

    while($row = $stmt->fetch()) {
        $return_arr[] =  $row['id'].' - '.$row['nome'] ;
    }

} catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();
}

echo json_encode($return_arr);
}
  

JS

$(".produto").autocomplete({
    source: "../../../centrolimp/assets/php/busca_produtos.php",
    minLength: 2
});


// Essa parte que insiro as linhas na tabela ...

contador++;


    var newRow = $("<tr>");
    var cols = "";

    cols += '<td class="contador valor_total" >' + contador + '</td>';
    cols += '<td><label text-align="center"><input type="text" name="produto' + contador + '" class="produto" /></label></td>';
    cols += '<td><label text-align="center"><input type="text" name="qtd' + contador + '"     class="qtd spinner" onkeyup="somenteNumeros(this);" /></label></td>';
    cols += '<td><label text-align="center"><input type="text" name="preco' + contador + '"   class="preco"  align="center" /></label></td>';
    cols += '<td class="col-md-2 total">R$ 0.00</td>';
    cols += '<td><a class="deleteLinha"> Excluir </a></td>';

    newRow.append(cols);

I'm already getting the right amount, I just need to split this result now.

    
asked by anonymous 14.03.2018 / 17:58

0 answers