Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

131
Vistas
Automatically send autocomplete option

I want to automatically send the selected autocomplete option after selecting, not needing to click on submit button or clicking out of the box, ive tried "onchange" but I have to click out of the box after autocompleting. Here is how the events are going right now:

The empty box:

enter image description here

Typing something:

enter image description here

After selecting:

enter image description here

The problem is that it only sends after I click somewhere else, I wanted it to automatically send after selecting the option. Finally, heres the code:

<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<form id="search_box" method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
    Busca por nome, ticker ou código CVM:
    <br>
    <input id="searchbox" type="text" name="searchbox" onchange="this.form.submit()">
</form>
<script>

$(function()
{
    var opac =  <?php echo json_encode($ressb); ?>;
    $( "#searchbox" ).autocomplete
    (
        {
            source: opac
        }
    );
}
);
</script>

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Ive tried the solutions provided using onkeyup with EventListener but couldnt make it to work, but found another topic with a solution that worked for me, by working directly in the autocomplete function, unfortunately I didnt found it before opening this question.

Here is the updated code:

<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<form id="search_box" method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
    Busca por nome, ticker ou código CVM:
    <br>
    <input id="searchbox" type="text" name="searchbox">
</form>
<script>
$(function()
{
    var opac =  <?php echo json_encode($ressb); ?>;
    var formac = document.getElementById("search_box");
    $( "#searchbox" ).autocomplete
    (
        {
            source: opac,
            select: function(event,ui)
            {
                $( "#searchbox" ).val(ui.item.value);
                formac.submit();
            }
        }
    );
}
);
</script>

Thanks for the answers!

about 4 years ago · Juan Pablo Isaza Denunciar

0

onchange event is not a "real" onchange, for your demand you need to use onkeyup event

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda