Use select data in input

2

I have a code that selects an option from the data that comes from the database. This part of the code is ok, it selects and brings.

The problem is that when I select this option , I need to populate 4 fields input automatically, with data coming from the database.

I can only show one die. I think I have to save this data to use in inputs , but I do not know how to do it.

I will post the code below commenting:

<?php


    require_once('requerimentoController.class.php');
        $requerimento = new requerimentoController;
        $acervoGrid = $requerimento->gridAcervos();//Aqui recebo os dados do BD
        $qtdRow = count($acervoGrid);
?>
<html>
    <script>
    function selecionar(){
        document.getElementById('tipo').value = document.getElementById('selectOK').value;
    }
    </script>
    <body>
    <select id="selectOK" onchange="selecionar()">
        <?php for($a = '0'; $a < $qtdRow; $a++){ ?> 

    <option value="<?=$acervoGrid[$a]['tipo'];?>"><?php echo $acervoGrid[$a]['tipo']; ?>
    /* Aqui seleciono qual o valor que quero da tabela*/
    <?php }?>
    </select></br>
    <input type="text" id="tipo"/> /*aqui mostro no input os valores correspondentes ao que selecionei no option com dados que vem do banco.
    <input type="text" id="marca"/>
    <input type="text" id="serie"/>
    <input type="text" id="modelo"/>
    </body>
</html>
    
asked by anonymous 03.12.2018 / 13:36

1 answer

0

Friend, you will need to use a javascript. When selecting the actuate in the inputs. I have an example for you:

<script>
$('#selectOK').change(function (){
var e = document.getElementById('selectOK');
var strDocumento = e.options[e.selectedIndex].value;

    if(strDocumento == "resultado1"){
        document.getElementById("tipo").value = "VALOR TIPO";
        document.getElementById("marca").value = "VALOR MARCA";
        /* etc..*/
    }
    if(strDocumento == "resultado2"){
        document.getElementById("tipo").value = "VALOR TIPO";
        document.getElementById("marca").value = "VALOR MARCA";
        /* etc..*/
    }
  });
</script>
    
03.12.2018 / 19:03