50projects50days/verify-account-ui/script.js
2020-11-04 11:18:57 -05:00

14 lines
393 B
JavaScript

const codes = document.querySelectorAll('.code')
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)
}
})
})