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

178
Views
Focus does not jump to another input field on mobile but does on desktop

This javascript work on desktop but not working on mobile. In mobile, focus does not jump to another input field.

const codes = document.querySelectorAll('.otp')

codes[0].focus()

codes.forEach((code, idx) => {
    code.addEventListener('keydown', (e) => {
        if (e.key >= 0 && e.key <= 9) {
            codes[idx].value = ''
            setTimeout(() => codes[idx + 1].focus(), 10)
        } else if (e.key === 'Backspace') {
            setTimeout(() => codes[idx - 1].focus(), 10)
        }
    })
});
<div class="d-flex flex-row">
<input class="form-control login_form_control otp" type="text" maxlength="1">
<input class="form-control login_form_control otp" type="text" maxlength="1">
<input class="form-control login_form_control otp" type="text" maxlength="1">
<input class="form-control login_form_control otp" type="text" maxlength="1">
<input class="form-control login_form_control otp" type="text" maxlength="1">
<input class="form-control login_form_control otp" type="text" maxlength="1">
</div>

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In mobile, after pressing enter, you need to wait more milliseconds of focusing other inputs :D You can try using 3000 ms in timeout or more to solve. In my project, it worked.

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!