how to pass data from mysql to textbox with js

0

Hello good afternoon, I need help with a problem. I want to pass the results to the textbox with js and I do not know how to just show it in a label ... Help .. thanks

<!DOCTYPE html>
<html lang="es">
    <head>
        <title>Autocompletado</title>
        <meta charset="utf-8">
        <script src="js/jquery-1.11.3.min.js"></script>
        <script src="js/jquery-ui.js"></script>
        <script>
            $(function(){
                $("#buscador").autocomplete({
                    source: 'buscador.php',
                    select: function(event, ui){
                        $("#resultado").html(
                            '<h2>Detalles del Usuario:</h2>'  + 
                            'Nombre de Usuario: ' +  ui.item.value + '<br>' + 
                            'id de usuario: ' +   ui.item.id + '<br>' + 
                            'pa: ' +   ui.item.pa + '<br>' + 
                            'cel: ' +   ui.item.cel 
                        );
                    }
                });
            });

        </script>
    </head>
    <body>
        <div id="buscar">
            Buscador<input type="text" name="buscador" id="buscador" />
        </div>
        <div id="resultado">

        </div><br><br><br><br><br>
        <div>
             <input type="text" name="nombre" id="nombre" >
              <input type="text" name="pa" id="pa" />
               <input type="text" name="telefono" id="telefono" />
        </div>
    </body>
</html>
    
asked by Jostin Joseph 28.02.2018 в 21:03
source

1 answer

0

In your function of select you must put the values as values , part you should add a hidden field with the value of id so that then the submit of your form works

<!DOCTYPE html>
<html lang="es">
    <head>
        <title>Autocompletado</title>
        <meta charset="utf-8">
        <script src="js/jquery-1.11.3.min.js"></script>
        <script src="js/jquery-ui.js"></script>
        <script>
            $(function(){
                $("#buscador").autocomplete({
                    source: 'buscador.php',
                    select: function(event, ui){
                        $("#resultado").html(
                            '<h2>Detalles del Usuario:</h2>'  + 
                            'Nombre de Usuario: ' +  ui.item.value + '<br>' + 
                            'id de usuario: ' +   ui.item.id + '<br>' + 
                            'pa: ' +   ui.item.pa + '<br>' + 
                            'cel: ' +   ui.item.cel 
                        );

                        // Seteando los valores
                        $("#id").val(ui.item.id);
                        $("#nombre").val(ui.item.value);
                        $("#pa").val(ui.item.pa);
                        $("#telefono").val(ui.item.cel);
                    }
                });
            });

        </script>
    </head>
    <body>
        <div id="buscar">
            Buscador<input type="text" name="buscador" id="buscador" />
        </div>
        <div id="resultado">

        </div><br><br><br><br><br>
        <div>
            <input type="hidden" name="id" id="id" > <!-- Colocar el ID  -->
            <input type="text" name="nombre" id="nombre" >
            <input type="text" name="pa" id="pa" />
            <input type="text" name="telefono" id="telefono" />
        </div>
    </body>
</html>
    
answered by 28.02.2018 / 21:12
source