0
When selecting the product in the list of suggestions Autocomplete I have to give TAB to complete the next fields, I wanted that as the Description field was filled in the other fields were filled out without having to use TAB
<script type='text/javascript'>
$(document).ready(function(){
$("input[name='descri']").blur(function(){
var $codigo_produto = $("input[name='codigo_produto']");
var $barcode = $("input[name='barcode']");
var $id = $("input[name='id']");
$.getJSON('function.php',{
descricao: $( this ).val()
},function( json ){
$codigo_produto.val( json.codigo_produto );
$barcode.val( json.barcode );
$id.val( json.id );
});
});
});
</script>
<!-- Fim do script de preenchimento automático dos campos a partir do campo Descrição -->
<br/><br/>
<div class="container">
<div class="col-lg-12">
<div class="col-lg-12">
<h3 align="center">Autocomplete utilizando jQuery, PHP e MySQL</h3><br />
<label>Descrição</label>
<input type="text" name="descri" id="descri" class="form-control" placeholder="Escreva aqui a descrição do produto"><br>
<div id="descriList"></div>
</div>
<div class="col-lg-4"><!-- Inicio Input Cóodigo do Produto-->
<label for="ex1">Código do Produto:</label>
<input type="text" required class="form-control" maxlength="13" name="codigo_produto"><br>
</div><!-- Fim Input Código do Produto -->
<div class="col-lg-4"><!-- Inicio Input Código EAN / Barcode -->
<label for="ex1">Código EAN:</label>
<input type="text" required class="form-control" maxlength="13" name="barcode"><br>
</div><!-- Fim Input Código EAN / Barcode -->
<div class="col-lg-4"><!-- Inicio Input ID -->
<label for="ex1">ID:</label>
<input type="text" disabled class="form-control" maxlength="13" name="id"><br>
</div><!-- Fim Input ID -->
</div>
</div>
</body>
</html>
<!-- Inicio Script para aparecer sugestões de produtos relacionados ao que esta sendo informado no input -->
<script>
$(document).ready(function(){
$('#descri').keyup(function(){
var query = $(this).val();
if(query != '')
{
$.ajax({
url:"search.php",
method:"POST",
data:{query:query},
success:function(data)
{
$('#descriList').fadeIn();
$('#descriList').html(data);
}
});
}
});
$(document).on('click', 'li', function(){
$('#descri').val($(this).text());
$('#descriList').fadeOut().change();
});
});
</script>
<!-- Fim Script para aparecer sugestões de produtos relacionados ao que esta sendo informado no input -->
Thanks but had already tried with Keyup in a different way, I tried your code and even then it was not
– Victor
@Victor you tried to remove the code that is at the end, leaving only one keyUp for this element?
– Gabriel
If I remove the code from the end, there will appear suggestions related to auto complete search on what is auto complete, are suggestions related to what was typed in the search, such as google search that as Voce type it completes the elements. This code of the end is for that, and the one of the beginning is for as I select a product the other fields are completed
– Victor
Yeah, from what I’ve seen, one doesn’t influence the other, so it should work. You receive an error and can identify if the call is made with the first keyUp?
– Gabriel
If I leave as keyUp event the first event that is what you sent is not called and nor run, already with Blur it fills the next fields from the Description, but after selecting a product from the list of products suggested by the autocomplete I have to give tab of the name input description to change the focus to another input and then yes complete / fill in the next fields . The code already works the problem is that wanted a better performance...
– Victor
In my example code I put keyUp (with uppercase in U), you came to try everything minusculo (keyup). I edited the answer to make it work.
– Gabriel
Yes, I put it with a minuscule "u", but I tried to click, but I also have to click inside the input for the fields to be completed... I’m cracking my head
– Victor
There is more Javascript and HTML code than informed?
– Gabriel
no, the strange thing is that they work, otherwise it would not even appear related product suggestions as for example, when typing Pumpkin, appear all database records that have pumpkin as first word, and then if I give tab it completes the following fields but, the way I want it I haven’t gotten it yet
– Victor