A functional example, it’s up to you to adapt to your case:
Select pulling all companies from the bank, call an event on onchange that will fill in the inputs according to the values searched in the database:
<select class="select" id="numEmpresa" name="numEmpresa" onchange='empresa(this.value,this.id)' autofocus required>
<option value='-1'>Digite Nº da Empresa</option>
<?php foreach($empresas as $row){ ?>
<option value='<?=$row['num_empresa']?>'>
<?=$row['num_empresa']?> - <?=$row['nm_empresa']?>
</option>
<?php } ?>
</select>
The event onchange company, takes the value of select and fills in the input honorary
<!-- Buscar Empresas -->
<script type='text/javascript'>
function empresa(id,select){
$('#honorario').attr("disabled",false);
$.post("autoCompleteSelect.php",{idEsc:id},function(retorno){
$('#honorarios').val(retorno);
}
});
}
</script>
<!-- ./ Buscar Empresas -->
Populate input according to function return:
<input type="text" id="honorarios" name="honorarios" >
The Script (autoCompleteSelect.php) that is called within the event enterprise, pulls from the bank the value of the input honorary and returns to function
$id = (int)$_POST['idEsc']; // id passado pelo select
list($resultados,$quantidade) = $select->selectTable('empresa','valor',NULL,"numero=".$id,NULL);
if($quantidade>0){
foreach ($resultados as $row) {
$dados = str_replace(".",",", $row['valor']);
}
}else{
$dados = '';
}
echo $dados;
Opa Bia , I’m sorry for the delay in responding , but could you give me an explanation of how to use this code ? I tried here a few times but could not adapt
– Matheus Goes
@Matheusgoes The first part is the select that has the names of the companies, according to the company that selects the value of the fee field (honorary input) is filled in according to the drawn value of the bank. The onchange script is responsible for calling the select (autoCompleteSelect.php) that searches the database. autoCompleteSelect.php is a separate file, in it Voce has access to the bank and looks for the necessary elements, in case the fee value to fill the honorary inputs.
– Bia
@Matheusgoes friend I know that my answer was very direct, watch this video that does the same thing of this script: https://www.youtube.com/watch?v=j4HMjjPj5IU, I’m sure you will get it so.
– Bia
Very obg , I managed to do following this video lesson :)
– Matheus Goes