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

169
Visualizações
How to use mouse to click/select the option?
<div class="form-dropdown">

<select value="" aria-labelledby="timeWindows_label" aria-invalid="false" aria-required="true" aria-describedby="timeslot-error" class=" form-dropdown-select" id="timeWindows">

<option value="8-12:30-12:45">12:30 – 12:45</option>
<option value="8-12:45-13:00">12:45 – 13:00</option>
<option value="8-13:00-13:15">13:00 – 13:15</option>

I would like to select the option by js, but it failed.

I used document.getElementById('timeWindows').value = '8-12:30-12:45', it returns error (timeslot is not selected)

I also used document.getElementById('timeWindows')[1].selected = true, it's still the same.

The displayed option has been changed, but the code returns error and nothing changed.

The errored code is below

<div class=" is-error form-dropdown">
<select value="" aria-labelledby="timeWindows_label" aria-invalid="true" aria-required="true" aria-describedby="timeslot-error" class=" form-dropdown-select" id="timeWindows">

<option value="8-12:30-12:45">12:30 – 12:45</option>
<option value="8-12:45-13:00">12:45 – 13:00</option>
<option value="8-13:00-13:15">13:00 – 13:15</option>

This is the successful example when I use the mouse to click the option.

<div class="form-dropdown">
<select value="8-12:45-13:00" aria-labelledby="timeWindows_label" aria-invalid="false" aria-required="true" aria-describedby="timeslot-error" class=" form-dropdown-select" id="timeWindows">
<option value="8-12:30-12:45">12:30 – 12:45</option>
<option value="8-12:45-13:00" selected="true">12:45 – 13:00</option>
<option value="8-13:00-13:15">13:00 – 13:15</option>

I also found the timeslot error in the source, but I don't know what the code refers to.

"timeSlotNotSelectedError":{"microEvents":[{"key":"eVar25","value":"transaction.co.fulfillment.timeslot.error.timeslot_not_selected","slot":"Pickup"}]},
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Check this jsfiddle: https://jsfiddle.net/zhuhang95/wjgra9fL/3/

Your code is working fine in jsFiddle. Make sure you use this method to change the option:

document.getElementById('timeWindows').selectedIndex = 0;

If your code looks exactly same, but you still get the error, then the problem is somewhere else in your code.

More info on how to select option using JS: https://stackoverflow.com/a/7373115/6122411

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