diff --git a/otp-box/index.js b/otp-box/index.js index 7b56609..f4e3059 100644 --- a/otp-box/index.js +++ b/otp-box/index.js @@ -24,6 +24,17 @@ function expireOTP() { function tackleOTPBoxes() { const boxes = document.getElementById("otp-box-list-id"); + + boxes.addEventListener('keydown', function(event) { + const key = event.key; + const preElement = event.target.previousElementSibling; + if (key === "Backspace" || key === 8 ) { + preElement.focus(); + event.target.value = ""; + return; + } +}); + boxes.addEventListener("input", function(e) { const target = e.target; const value = target.value; @@ -83,4 +94,4 @@ function init() { setTimeout(generateOTP, 2000); } -init(); \ No newline at end of file +init();