-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
50 lines (50 loc) · 1.73 KB
/
Copy pathindex.html
File metadata and controls
50 lines (50 loc) · 1.73 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<input tabindex="1" placeholder="1">
<input tabindex="2" placeholder="2" style="display: none">
<input tabindex="3" placeholder="3" style="display:none">
<input tabindex="4" placeholder="4">
<input tabindex="5" placeholder="5">
</body>
<script>
let inputs = document.querySelectorAll("input[tabindex],select[tabindex],textarea[tabindex]");
for (let i = 0; i < inputs.length; i++) {
inputs[i].addEventListener("keypress", function(e) {
if (e.which == 13) {
e.preventDefault();
let nextInput = document.querySelectorAll('[tabindex="' + (this.tabIndex + 1) + '"]');
let index = (nextInput > 1) ? nextInput.length-1 : 0;
if (nextInput.length === 0) {
console.log("Last!");
nextInput = document.querySelectorAll('[tabindex="1"]');
} else if (nextInput[index].style.display !== "none" && nextInput.length !== 0) {
console.log("Ja");
} else {
let counter = [];
console.log("Nee");
for (let j = 1; j < inputs.length; j++) {
nextInput = document.querySelectorAll('[tabindex="' + (this.tabIndex + j) + '"]');
index = (nextInput > 1) ? nextInput.length-1 : 0;
if (nextInput[index].style.display !== "none" && nextInput.length !== 0) {
console.log("Match!");
counter.push(j);
break;
}
}
nextInput = document.querySelectorAll('[tabindex="' + (this.tabIndex + counter[0]) + '"]');
counter = [];
}
nextInput[index].focus();
}
})
}
</script>
</html>