Pick up auto complete ID and move to another auto complete form as parameter

Asked

Viewed 667 times

1

I am setting up a register where I select the state and an ajax search the cities the customer selects the city show a form for him to type the name of the neighborhood where I use auto complete my question is how to get the id of this form/ neighborhood that he found step to another form that should use the form/neighborhood id to perform new auto complete and after that send to a script that will insert everything into the databank.

What I already have is the following auto complete code I would like help to assemble that second part

busca_bairro.php

$pdo = new PDO("mysql:host=localhost; dbname=$db", "$user", "$senha",
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$dados = $pdo->prepare("SELECT * FROM bairro");
$dados->execute();
echo json_encode($dados->fetchAll(PDO::FETCH_ASSOC));

html

<input type="text" id="txtNome" name="txtNome" size="60"/>

<script src="jquery/jquery-ui-1.11.4/jquery-ui.js"></script>    

<script type="text/javascript">
$(document).ready(function() {
// Captura o retorno do retornaCliente.php
    $.getJSON('busca_bairro.php', function(data){
    var dados = [];
    // Armazena na array capturando somente o nome do EC
    $(data).each(function(key, value) {
        dados.push(value.nome);
    });
    // Chamo o Auto complete do JQuery ui setando o id do input, array com os dados e o mínimo de caracteres para disparar o AutoComplete
    $('#txtNome').autocomplete({ source: dados, minLength: 3});
    });
});

</script>
  • Voce has already tried to retouch the id in this getJson and store it in an Hidden ho html input?

  • Israel I really don’t know how to do that I wonder if you can help me with that!

1 answer

0

Silva, as you have not posted your entire form, there is no way to know if in the same html file you have the php tags.

If you have, just change the line below:

of:

$.getJSON('busca_bairro.php', function(data){

for:

$.getJSON('busca_bairro.php?id=<?=$id ?>', function(data){
  • Hi @prmas posted the pages so you can look

Browser other questions tagged

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