Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
Passing ID in two different select function into 1 const function in jQuery?

I have 2 different select function that I'll use and get the id from the two different select and pass it into the 1 main function. But I have problem with getting the id from the select function.

What is the correct way on how to pass the id of cat_id and role_id into the getMyMode(a,b)

$(document).ready(function() {

  $("#cat").change(function() {

    let cat_id = $(this).val();
    getMyMode(cat_id);

  });

  $("#role").change(function() {
    let role_id = $(this).val();
    getMyMode(role_id);
  });

});
const getMyMode = (a, b) => {
  console.log(a, b);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="col-lg-4">
  <label class="form-label"> Category</label>
  <select class="form-control mb-3" id="cat">
    <option value="99" hidden> Choose Category</option>
    <option value="0">Cat 1</option>
    <option value="1">Cat 2</option>
  </select>
</div>

<div class="col-lg-4">
  <label class="form-label"> Role</label>
  <select class="form-control mb-3" id="role">
    <option value="99" hidden>Choose Role</option>
    <option value="23">Role 1</option>
    <option value="24">Role 2</option>
  </select>
</div>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Like this

const getMyMode = (a, b) => { console.log(a, b); };

$(function() { // when page has loaded

  $("#cat, #role").on("change", function() { // when either has changed
    let role_id = $("#role").val();
    let cat_id = $("#cat").val();
    getMyMode(cat_id,role_id);
  });

});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="col-lg-4">
  <label class="form-label"> Category</label>
  <select class="form-control mb-3" id="cat">
    <option value="99" hidden> Choose Category</option>
    <option value="0">Cat 1</option>
    <option value="1">Cat 2</option>
  </select>
</div>

<div class="col-lg-4">
  <label class="form-label"> Role</label>
  <select class="form-control mb-3" id="role">
    <option value="99" hidden>Choose Role</option>
    <option value="23">Role 1</option>
    <option value="24">Role 2</option>
  </select>
</div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda