-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform_multi_step.html
More file actions
91 lines (78 loc) · 2.02 KB
/
form_multi_step.html
File metadata and controls
91 lines (78 loc) · 2.02 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<div class="multi-step-form">
<div class="step active">Step 1</div>
<div class="step">Step 2</div>
<div class="step">Step 3</div>
</div>
<form id="form">
<div class="form-step active">
<label>Name:</label>
<input type="text">
<button type="button" onclick="nextStep()">Next</button>
</div>
<div class="form-step">
<label>Email:</label>
<input type="email">
<button type="button" onclick="prevStep()">Back</button>
<button type="button" onclick="nextStep()">Next</button>
</div>
<div class="form-step">
<label>Password:</label>
<input type="password">
<button type="button" onclick="prevStep()">Back</button>
<button type="submit">Submit</button>
</div>
</form>
<script>
let stepIndex = 0;
const steps = document.querySelectorAll(".form-step");
const indicators = document.querySelectorAll(".step");
function showStep(index) {
steps.forEach((step, i) => {
step.classList.toggle("active", i === index);
indicators[i].classList.toggle("active", i === index);
});
}
function nextStep() {
if (stepIndex < steps.length - 1) stepIndex++;
showStep(stepIndex);
}
function prevStep() {
if (stepIndex > 0) stepIndex--;
showStep(stepIndex);
}
</script>
<style>
.multi-step-form {
display: flex;
gap: 10px;
margin-bottom: 10px;
}
.step {
width: 60px;
height: 30px;
text-align: center;
line-height: 30px;
background: #ddd;
border-radius: 5px;
transition: 0.3s;
}
.step.active {
background: #4caf50;
color: white;
}
.form-step {
display: none;
}
.form-step.active {
display: block;
}
button {
margin-top: 10px;
padding: 8px 15px;
background: #3498db;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
</style>