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

112
Visualizações
html input element will not update to for loop

The text in the input immediately just skips to 99. Is there any way I can make it display the i variable, while it's iterating?

<input id="test" type="text">
<script>
    for(let i = 0; i < 100; i++){
    document.getElementById("test").value = String(i);
  }
</script>

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

0

You can use setInterval to call your function at whatever interval you like:

let i = 0;
setInterval(function() {
  if (i < 100) {
    document.getElementById("test").value = String(i);
    i++;
  }
}, 100)
<input id="test" type="text">

Your way won't work without some sort of delay because the entire loop executes in milliseconds and is too fast for the eye to see.

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