-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
81 lines (66 loc) · 2.29 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
let submitBtn = document.getElementById("submit");
const info = {
student_name: '',
email: '',
url: '',
website: '',
gender: '',
skillArr: [],
}
const getData = () => {
info.student_name = document.getElementById('name').value;
info.email = document.getElementById('email').value;
info.url = document.getElementById('url').value;
info.website = document.getElementById('website').value;
info.gender = document.querySelector('input[name="male-female"]:checked').value;
let skills = document.querySelectorAll('.checkbox:checked');
info.skillArr = [];
skills.forEach((item) => {
info.skillArr.push(item.value);
})
if (localStorage.getItem("infoSection") === null) {
infoItem = [];
}
else {
infoItem = JSON.parse(localStorage.getItem("infoSection"))
}
infoItem.push(info);
localStorage.setItem("infoSection", JSON.stringify(infoItem));
}
const showData = () => {
let cardContainer = document.getElementById("cardContainer");
let cards = '';
let getLocalStorage = localStorage.getItem("infoSection");
if (getLocalStorage === null) {
console.log("null");
}
else {
cardDivArr = JSON.parse(getLocalStorage);
cardDivArr.forEach((item, index) => {
cards += `<div class="card">
<img src=${item.url} alt="Profile Picture">
<div class="info">
<p>Name : ${item.student_name}</p>
<p>Email : ${item.email}</p>
<p>Website : <a href="${item.website}">Click here</a></p>
<p>Gender : ${item.gender}</p>
<p>Skills : ${item.skillArr.join(", ")}</p>
<button onclick="deleteData(${index})">Delete</button>
</div>
</div>`;
})
}
cardContainer.innerHTML = cards;
}
const deleteData = (index) => {
let getList = JSON.parse(localStorage.getItem("infoSection"));
getList.splice(index, 1);
localStorage.setItem("infoSection", JSON.stringify(getList));
window.location.reload();
}
showData();
submitBtn.addEventListener(('click'), () => {
getData();
// console.log(student_name, email, url, website, gender, skillArr);
showData();
})