Popular form already created with PHP (Mysql)

0

I need to populate a form with Mysql database information in the onChange event of an input Select.

I know how to create a form of 0 by filling in the values property, but filling a form already created I'm not getting.

input type="button" class="botao_form1" onclick="ativarform()" value="EDITAR">
                                <input type="submit" class="botao_form1" value="CADASTRAR">
                                <script>
                                    function ativarform(){
                                        document.getElementById("sobrenome_cliente").disabled = false;
                                        document.getElementById("idade_cliente").disabled = false;
                                        document.getElementById("telefone_cliente").disabled = false;
                                        document.getElementById("estado_cliente").disabled = false;
                                        document.getElementById("endereco_cliente").disabled = false;                                           
                                        document.getElementById("cidade_cliente").disabled = false; 
                                    }

                                    function actionform(){
                                        /* AQUI O FORM DEVE RECEBER AS INFORMAÇÕES DO BANCO */
                                        document.getElementById("sobrenome_cliente").disabled = true;
                                        document.getElementById("idade_cliente").disabled =  true;
                                        document.getElementById("telefone_cliente").disabled =  true;
                                        document.getElementById("estado_cliente").disabled =  true;
                                        document.getElementById("endereco_cliente").disabled =  true;                                       
                                        document.getElementById("cidade_cliente").disabled = true;      
                                    }
                                </script>
                                <?php 
                                        function popula(){
                                            $conexao = conectar();
                                            $nome = 'nome_ciente';
                                            $sql = mysqli_query($conexao, "SELECT * FROM cliente WHERE nome='$nome'");
                                            $row = mysqli_fetch_array($sql);
                                        }
                                ?>
    
asked by anonymous 01.03.2017 / 16:51

1 answer

1

Patrick, I do not think you understand the way to change a form without reloading the page (I believe this is what you're trying to do).

The operation looks something like this:

Theform"talk" with the server without reloading with the page, so you "need" to call a second page that assembles the options (or until the whole select), then it would look like this, your page static page with the two forms:

One to choose from:

<form>
 <select id="marca">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
 </select> 
</form>

Another to be populated by choosing the first one:

<form>
 <select id="modelos">
 </select> 
</form>

And a php page to receive and mount the options

<?php 
  function popula(){
           $conexao = conectar();
           $nome = 'nome_ciente';
           $sql = mysqli_query($conexao, "SELECT * FROM cliente WHERE nome='$nome'");
           $row = mysqli_fetch_array($sql);
         }
?>

And a loaded script:

$("select#marca").on("change", function () {
  $.getJSON( "/pesquisa.php", function( data ) {
    var items = [];
    $.each( data, function( key, val ) {
      items.push("<option value="+key+">"+val+"</option>");
    });

    $( "select#modelo").html(items);
  });    
});
    
01.03.2017 / 23:29