Get the ComboBox value automatically with Jquery via POST [duplicate]

0

I do not know if it was clear in the title, but who is old should remember that Dreamweaver had a Jump function that was very used in combobox. How would I make this option with Jquery within the following reasoning:

<label for="filtro">Registros:</label>
<select name="Filtrar" id="filtro" class="form-control">
  <option value="10">10</option>
  <option value="50">50</option>
  <option value="100">100</option>
</select>

When selecting the desired log amount, I would take it as a post directly and automatically play this method:

        $filtro = $_POST["Filtrar"];
   echo $metodos->listarUsuarios($filtro);

Listing method Users ()

 public function listarUsuarios($filtro)
    {
       $limite = ($filtro == '')?'10':$filtro;
       $sql = mysqli_query($this->conexao,"SELECT * FROM tabela LIMIT ".$limite.";");
      .....
    }

Is this possible with Jquery? It can be with JavaScript as well.

    
asked by anonymous 22.12.2018 / 15:20

1 answer

0

The jQuery script that returns the value of an option of a select element when you choose one of them is as follows:

$('#filtro').on('change', function(){
  let quantidade = $(this).val();
  console.log(quantidade);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><labelfor="filtro">Registros:</label>
<select name="Filtrar" id="filtro" class="form-control">
  <option value="10">10</option>
  <option value="50">50</option>
  <option value="100">100</option>
</select>
  

Note : The script can be created with Vanilla JS

    
22.12.2018 / 15:54