6
I have the following script
<script type="text/javascript">
$().ready(function() {
$("#course").autocomplete("teste1.php", {
width: 260,
matchContains: true,
selectFirst: false
});
});
</script>
That takes the turn from here:
$q = strtolower($_GET["q"]);
if (!$q) return;
list($resultados,$quantidade) = $select->selectTable('f_tb_empresas','id_empresa,nm_empresa',NULL,"nm_empresa LIKE '%".$q."%'",NULL);
foreach ($resultados as $row) {
$linha['value'] = $row['nm_empresa'];
$linha['id'] = $row['id_empresa'];
}
echo json_encode($linha);
And the result comes to the input:
<input type="text" name="course" id="course" />
The result comes like this: {"value":"Alameda dos anjos","id":"39"}
, but wanted the id to be for one input and value for another.
How do I do this with Jquery?
Thank you
the value of $q is being passed directly to the untreated query before? >.<
– Renato Tavares
@Renatotavares for now yes
– Bia
Where is the JS that returns the JSON ?
– Diego Souza
@Taopaipai This is my question, how do I return this value? because the way it is in the code the source goes directly to input
– Bia
This script that has the function
autocomplete, has the link ?– Diego Souza
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type='text/javascript' src="js/jquery.autocomplete.js"></script><link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />@Taopaipai– Bia
Yes, but you have the LINK of the documentation of this
jquery.autocomplete.js? If you don’t, fine. Just explain to me one thing... you said you want thevaluein ainputand theidin anotherinput. At what point do you want this ? When do you return the data or when do you choose an ? If it’s the first option it doesn’t have to be the two in the sameinput?– Diego Souza
@Taopaipai when I choose an option, I would like the one input to receive the value and the other the id
– Bia
I get it, for that you have to see the elements it generates under the
input. Open the Chrome Inspect Element and type something into the field to run theautocomplete. In the result that appears right click on a result and go to Inspect Element. Put a print on your post of what appears.– Diego Souza
@Taopaipai image link: (https://drive.google.com/file/d/0BwH8KrvYWlojV3JSbkN3d2pHbU0/view?usp=sharing)
– Bia