Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!