web_defender/Device/static/accounts/js/otpScript.js
2024-12-09 13:43:16 +05:30

32 lines
722 B
JavaScript

const inputs = document.getElementById("inputs");
inputs.addEventListener("input", function (e) {
const target = e.target;
const val = target.value;
if (isNaN(val)) {
target.value = "";
return;
}
if (val != "") {
const next = target.nextElementSibling;
if (next) {
next.focus();
}
}
});
inputs.addEventListener("keyup", function (e) {
const target = e.target;
const key = e.key.toLowerCase();
if (key == "backspace" || key == "delete") {
target.value = "";
const prev = target.previousElementSibling;
if (prev) {
prev.focus();
}
return;
}
});