Pick up the Combobox value automatically with Jquery via POST

Asked

Viewed 92 times

0

I don’t know if I made myself clear in the title, but whoever’s old-fashioned might remember that Dreamweaver had a jump function that was used a lot 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 amount of record, I would take it as a post directly and play within that method automatically:

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

List method()

 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.

  • 1

    Putz. You’re right Leandrade. I had completely forgotten this post! Thanks!

1 answer

0


The jQuery script that returns the value of an element option select when choosing one of them is the following:

$('#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>
<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>

Note: Script can be created with Vanilla JS

  • Thank you Maujor

Browser other questions tagged

You are not signed in. Login or sign up in order to post.