forked from ShaifArfan/30days30submits
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
45 lines (41 loc) · 1.15 KB
/
main.js
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
const steps = Array.from(document.querySelectorAll('form .step'));
const nextBtn = document.querySelectorAll('form .next-btn');
const prevBtn = document.querySelectorAll('form .previous-btn');
const form = document.querySelector('form' );
nextBtn.forEach(button => {
button.addEventListener('click', () => {
changeStep('next');
})
});
prevBtn.forEach( button => {
button.addEventListener('click', () => {
changeStep('prev');
})
})
form.addEventListener('submit', (e) => {
e.preventDefault();
const inputs = [];
form.querySelectorAll('input').forEach(input => {
const { name, value } = input;
inputs.push({name , value})
});
console.log(inputs)
form.reset();
let index = 0;
const active = document.querySelector('.active');
index = steps.indexOf(active);
steps[index].classList.remove('active');
steps[0].classList.add('active');
})
function changeStep(btn){
let index = 0;
const active = document.querySelector('.active');
index = steps.indexOf(active);
steps[index].classList.remove('active');
if(btn === 'next'){
index++;
}else if(btn === 'prev'){
index --;
}
steps[index].classList.add('active');
}