1
Hello, everyone. I have a question regarding a form.
I have a form in which your SELECT has your OPTION filled through PHP (A select made in a create file).
However, there are 3 fields (SELECT) that are interconnected. So I would like when I change one of these fields the other fields will be changed as well. Let me show you a page print.
Above, we have the fields COD, COMPANY and TAXATION. In the database, each company has a code (which is the COD field) and taxation (which is the field TAXATION).
I would like that when I change the COD field, the COMPANY field select goes to the company (option) corresponding to the COD field code and vise and versa.
Below follows the SELECT padding code.
<!-- LINHA -->
                        
<div class="col-lg-12 alinhar-texto-no-centro" id="selecionar-empresas">
  <h3 class="alinhar-texto-no-centro">Selecionar Empresa</h3>
  <!-- CAMPO CODIGO DA EMPRESA -->
  <div class="form-group col-lg-2">
    <label for="codigo-empresa">COD</label>
    <select name="codigo-empresa" id="codigo-empresa" class="input form-control">
      <?php
      $i = 1;
      while($registros = $query_pegar_cod -> fetch_assoc())
      {                                                                                     
        $emp = $registros['COD'];
        echo "<option id='$i'>$emp</option>";
        $i++;                                           
      }
      ?>            
    </select>
  </div>
  <!-- CAMPO EMPRESA -->
  <div class="form-group col-lg-5">
    <label for="empresa">Empresa</label>
    <select name="empresa" id="empresa" class="input form-control">
      <?php
      $j = 1;
      while($registros = $query_pegar_empresa -> fetch_assoc())
      {
        $empr = utf8_decode($registros['EMPRESAS']);
        echo "<option id='$j'>$empr</option>";                                          
      $j++;
      }
      ?>                    
    </select>
  </div>
  <!-- CAMPO TRIBUTAÇÃO -->
  <div class="form-group col-lg-5">
    <label for="tributacao">Tributação</label>
    <select name="tributacao" id="tributacao" class="input form-control">
      <?php
        while($registros = $query_pegar_tributacao -> fetch_assoc())
        {
          $empre = utf8_decode($registros['TRIBUTACAO']);
          echo "<option>$empre</option>";
        }
      ?>                                
    </select>
  </div>
I know the explanation wasn’t so succinct, but I hope you can understand.
Thank you!

Just make an ajax call to the PHP server at the event
onchangeof the first<select>which must return the data needed to fill in the second and third<select>. Add the code you’ve tried– Costamilam
Guilherme, you say the code I’ve tried in ajax ? I’ve tried some things, but by not working out I ended up erasing. Could you suggest something regarding jquery, ajax ... that I could use ? I will edit the question and add the code of how I filled the selects.
– Gato de Schrödinger