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

87
Visualizações
javascript select the second option automatically?

How can I use javascript, to automatically select Option value 2? But I have and as the same id ..

var index = 1; /* option do select*/
document.getElementById("594951-Cor").options.selectedIndex = index;
<div id="594951-Cor" name="594951-Cor">

<select id="594951-Cor" name="594951-Cor" class="">
<option value="0">Selecione...</option>
<option value="1">Color 01</option>
<option value="2">Color 02</option>
</select>

</div>

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

After solve the problem with ID's (change the duplicated id's), if you want to select by value, just assign on the select node:

document.getElementById("594951-Cor").value = "2";

assuming that you want to select <option value="2">Color 02</option> and the id of the select node is "594951-Cor".

The "2" is the value of the `option, not the index.

about 4 years ago · Santiago Gelvez 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