| Server IP : 14.225.216.240 / Your IP : 216.73.216.26 Web Server : nginx/1.20.1 System : Linux localhost.localdomain 5.14.0-596.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jun 27 16:02:33 UTC 2025 x86_64 User : taidh ( 1001) PHP Version : 8.3.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/pts/st/assets/ |
Upload File : |
const inputs = document.querySelectorAll(".otp-field > input");
const button = document.querySelector(".btn");
const codeField = document.querySelector("input[name=code]");
window.addEventListener("load", () => inputs[0].focus());
button.setAttribute("disabled", "disabled");
inputs[0].addEventListener("paste", function (event) {
event.preventDefault();
const pastedValue = (event.clipboardData || window.clipboardData).getData(
"text"
);
const otpLength = inputs.length;
for (let i = 0; i < otpLength; i++) {
if (i < pastedValue.length) {
inputs[i].value = pastedValue[i];
inputs[i].removeAttribute("disabled");
inputs[i].focus;
} else {
inputs[i].value = ""; // Clear any remaining inputs
inputs[i].focus;
}
}
});
inputs.forEach((input, index1) => {
input.addEventListener("keyup", (e) => {
const currentInput = input;
const nextInput = input.nextElementSibling;
const prevInput = input.previousElementSibling;
if (currentInput.value.length > 1) {
currentInput.value = "";
return;
}
if (
nextInput &&
nextInput.hasAttribute("disabled") &&
currentInput.value !== ""
) {
nextInput.removeAttribute("disabled");
nextInput.focus();
}
if (e.key === "Backspace") {
inputs.forEach((input, index2) => {
if (index1 <= index2 && prevInput) {
input.setAttribute("disabled", true);
input.value = "";
prevInput.focus();
}
});
}
button.classList.remove("active");
button.setAttribute("disabled", "disabled");
codeField.value = "";
const inputsNo = inputs.length;
if (!inputs[inputsNo - 1].disabled && inputs[inputsNo - 1].value !== "") {
button.classList.add("active");
button.removeAttribute("disabled");
let code = '';
inputs.forEach((input, _idx) => {
code += input.value;
});
codeField.value = code;
return;
}
});
});