-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
142 lines (139 loc) · 3.68 KB
/
script.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
let input=document.querySelectorAll(".input");
let submit=document.querySelector("button");
let form=document.querySelector("#form");
let proceed=document.querySelector("#popup");
let thank=document.querySelector("#thanku");
let loader=document.querySelector("#loader");
let cardno=document.querySelector("#cardno");
let cvc=document.querySelector("#cvccard");
let nam=document.querySelector("#namecard");
let date=document.querySelectorAll(".card1");
const input1=()=>{
let l=input[0].value.trim().length;
if(l!=0)
{
for(let ch of input[0].value)
{
if(isNaN(ch)==false && ch!=" "){
error(input[0]);
return false;
}
}
errorfree(input[0]);
return true;
}
else{
error(input[0]);
return false;
}
}
const input2=()=>{
let l=input[1].value.length;
if(l==12 && isNaN(input[1].value)==false)
{
errorfree(input[1]);
return true;
}
error(input[1]);
return false;
};
const input4=()=>{
if(parseInt(input[3].value)>=24 && parseInt(input[3].value)<100 && input[3].value.length==2)
{
errorfree(input[3]);
return true;
}
error(input[3]);
return false;
};
const input5=()=>{
let l=input[4].value.length;
if(l==3 && isNaN(input[4].value)==false)
{
errorfree(input[4]);
return true;
}
error(input[4]);
return false;
};
const error=(x)=>{
x.setAttribute("class","input redborder");
let X=x.parentElement;
X.children[X.childElementCount-1].setAttribute("style","");
x.value="";
};
const errorfree=(x)=>{
x.setAttribute("class","input");
let X=x.parentElement;
X.children[X.childElementCount-1].setAttribute("style","visibility:hidden");
};
let k=0;
submit.addEventListener("click",()=>{
let arr=[input1(),input2(),true,input4(),input5()];
setTimeout(()=>{
for(let i of arr)
{
if(i==true)
k=0;
else
{
k=1;
break;
}
}
if(k==0){
thank.setAttribute("style","display:flex");
form.setAttribute("style","display:none");
proceed.addEventListener("click",()=>{setTimeout(()=>{
let x=confirm("Do you want another form?");
if(x==true)
resetcard();
else
location.href="https://www.google.com/";},"1000");
})
}},"1000");
for(let i=0;i<5;i++){
if(arr[i]==true)
cardupdate(input[i].value,i);
else
cardreset(i);
}
});
const cardupdate=(val,index)=>{
if(index==0)
nam.innerText=val;
if(index==1)
cardno.innerText=val.slice(0,4).concat(" ".concat(val.slice(4,8).concat(" ".concat(val.slice(8)))));
if(index==2)
date[0].innerText=val;
if(index==3)
date[1].innerText=val;
if(index==4)
cvc.innerText=val;
};
const cardreset=(index)=>{
if(index==0)
nam.innerText="XXX";
if(index==1)
cardno.innerText="0000 0000 0000";
if(index==2)
date[0].innerText="MM";
if(index==3)
date[1].innerText="YY";
if(index==4)
cvc.innerText="000";
};
const resetcard=()=>{
thank.setAttribute("style","display:none");
console.log(thank);
form.setAttribute("style","display:block");
console.log(form);
for(let i=0;i<5;i++)
{
if(i==2)
input[i].value="01";
else
input[i].value="";
cardreset(i);
}
};