-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignup.js
58 lines (48 loc) · 1.74 KB
/
signup.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
const fName = document.querySelector('#fName');
const lName = document.querySelector('#lName');
const uName = document.querySelector('#uName');
const mail = document.querySelector('#mail');
const pWord = document.querySelector('#pWord');
const sex = document.querySelector('#sex');
const age = document.querySelector('#age');
const login = document.querySelector('#login')
const sForm = document.querySelector('#sForm');
sForm.addEventListener('submit', signUp);
let savedData = JSON.parse(localStorage.getItem('details'));
function signUp(e) {
e.preventDefault()
let pDetails = {
'first Name': fName.value,
'last Name': lName.value,
'user Name': uName.value,
email: mail.value,
password: pWord.value,
sex: sex.value,
age: age.value
}
let detailsArr;
if (fName.value == '' || lName.value == '' || uName.value == '' || mail.value == '' || pWord.value == '' || sex.value == '' || age.value == '') {
alert('Please fill in all the details')
} else if (localStorage.getItem('details') == null) {
detailsArr = [];
detailsArr.push(pDetails);
localStorage.setItem('details', JSON.stringify(detailsArr));
location.replace('login.html');
} else if (localStorage.getItem('details')) {
detailsArr = JSON.parse(localStorage.getItem('details'));
let filterArr = detailsArr.filter((item) => {
return item['user Name'] === uName.value
});
if (filterArr.length > 0) {
alert('User name is already in use. Please choose another user name')
} else {
detailsArr.push(pDetails);
localStorage.setItem('details', JSON.stringify(detailsArr));
location.replace('login.html');
}
}
}
login.addEventListener('click', logIn);
function logIn() {
location.replace('login.html')
}