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

161
Views
KeyUp event registering several times

I'm creating a wordle like input scheme, where each input has only 1 character, and typing in one automatically sends you to the next. The problem is, of course, you can't hit backspace to go to the previous one, so I implemented it with the following code:

let inputs = document.getElementsByTagName("input");

document.body.addEventListener("keyup", function (e) {
  if (e.keyCode === 8) {
    for (let i = 0; i < inputs.length; i++) {
      if (inputs[i].value == "" && i > 0 && inputs[i] == document.activeElement) {
        inputs[i - 1].value = "";
        inputs[i].value = ""
        inputs[i - 1].focus();
        break
      }
    }
  }
});

I expect the code to simply register the backspace key just once, but instead it reports it a number of times, causing the whole row to be erased when I hit the key just once. Sometimes it can be just 10, other times hundreds. Why is this? How can I fix this? I'd additionally like to mention that I do not want to use jQuery and want to keep this pure JavaScript.

about 4 years ago · Juan Pablo Isaza
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!