-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (30 loc) · 1.18 KB
/
script.js
File metadata and controls
34 lines (30 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const inputs = document.querySelectorAll('.otp-card-inputs input');
const button = document.querySelector('.otp-card button');
inputs.forEach((input, index) => {
input.onkeyup = (e) => {
const currentElement = e.target;
const nextElement = input.nextElementSibling;
const prevElement = input.previousElementSibling;
if (prevElement && e.keyCode === 8) {
if (currentElement.value === '') {
prevElement.value = '';
prevElement.focus();
}
} else {
const reg = /^[0-9]+/;
if (!reg.test(currentElement.value)) {
currentElement.value = currentElement.value.replace(/\D/g, '');
} else if (currentElement.value) {
if (nextElement) {
nextElement.focus();
}
}
}
// Check if all input fields have values
const allInputsFilled = Array.from(inputs).every((input) => input.value !== '');
if (allInputsFilled) {
button.removeAttribute('disabled');
button.style.backgroundColor = 'blueviolet'; // Change the button color here
}
};
});