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

183
Visualizações
jquery getting options text from different select ids in a function

In the code below if options from both color_select and size_select are selected, only the latest selected option is logged only(e.g either red or small is logged if both are selected depending whichever is selected later). How to log options from both the select(color_select and size_select) on change in one function when option from either of the select is changed (i.e log both red and small if both are selected)?

<h6>Choose Color</h6>
<select id="color_select" name="color" class="form-control" required="">
    <option value="" disabled="" selected="">Select</option>
    <option value="red">Red</option>
    <option value="blue">Blue</option>
    <option value="white">White</option>
</select>

<h6>Choose Size</h6>
<select id="size_select" name="size" class="form-control" required="">
    <option value="" disabled="" selected="">Select</option>
    <option value="small">Small</option>
    <option value="large">Large</option>
    <option value="medium">Medium</option>
</select>

   $('#color_select','#size_select').on('change' , function() {
    // Code here
    var $this = $(this);
   if($this.find('option:selected').index() !== 0){

       text = $this.find('option:selected').text();
       console.log(text);
   }     
}).change()
about 4 years ago · Juan Pablo Isaza
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