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

90
Visualizações
click specific option using javascript or jquery

I tried googling this but I am getting only on event trigger searches instead of what I am looking for.

I want to dynamically click on any of the options in the select dropdown by using the value or the text if possible.

HTML

<select id="certainspamselectid" name="certainspamselect" style="margin-left: 165px;">
   <option value="0">permanently deleted</option>
   <option value="4">moved to admin quarantine</option>
   <option value="1">moved to junk email folder</option>
   <option value="5">delivered to inbox with tag</option>
   <option value="2">delivered to inbox</option>
</select>

I am not sure if I need to use something with $("#certainspamselectid").click..... but I am not sure what to use after click. I would have tried more things but my google searches keep pinpointing me for on event triggers when I just want to click on one of these options using either JS or jQuery.

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

0

  • With <select> what you need is .change instead of .click Here is a quick example .. change the $value and check again

$("#certainspamselectid").on('change' , function(){
  console.log("Value Changed To: "+$(this).val());
  
  if($(this).val() == 5){
    console.log("value 5 is selected");
  }
});

let $value = 4;
$("#certainspamselectid").val($value).change();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="certainspamselectid" name="certainspamselect" style="margin-left: 165px;">
   <option value="0">permanently deleted</option>
   <option value="4">moved to admin quarantine</option>
   <option value="1">moved to junk email folder</option>
   <option value="5">delivered to inbox with tag</option>
   <option value="2">delivered to inbox</option>
</select>

about 4 years ago · Juan Pablo Isaza Relatório

0

I have read your problem and honestly, I can't understand what you want exactly. However, it looks like you want to select some certain option of the select dropdown. If that's right, you don't need to call some kind of click function.

You can do it easily with jQuery.

For example, imagine that you are going to select third option - "moved to junk email folder". Then you can select it by code like below.

$("#certainspamselectid").val(1);

If my answer is not enough for you, let me know detail of your problem.

about 4 years ago · Juan Pablo Isaza Relatório

0

why don't you simply change the value of the select like this

$("#certainspamselectid").val(4)

It will automatically show the text from the selected option

I don't think that clicking on an option would help you

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