-
Notifications
You must be signed in to change notification settings - Fork 0
/
question11.htm
120 lines (114 loc) · 3.68 KB
/
question11.htm
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>JS For Beginners</title>
<!-- <link rel="stylesheet" href="style.css"> -->
<style>
/* * {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica, sans-serif;
line-height: 1.6;
}
ul {
list-style: none;
}
ul li {
padding: 5px;
background: #f4f4f4;
margin: 5px 0;
}
header {
background: #f4f4f4;
padding: 1rem;
text-align: center;
}
.container {
margin: auto;
width: 500px;
overflow: auto;
padding: 3rem 2rem;
}
#my-form {
padding: 2rem;
background: #f4f4f4;
}
#my-form label {
display: block;
}
#my-form input {
width: 100%;
padding: 8px;
margin-bottom: 10px;
border-radius: 5px;
border: 1px solid #ccc;
}
.btn {
display: block;
width: 100%;
padding: 10px 10px;
border: 0;
background: #333;
color: #fff;
border-radius: 5px;
margin: 5px 0;
} */
</style>
</head>
<body>
<div id="list">
<form>
<label for="name" class="form-group">Name</label>
<input type="text" class="form-control" id="name" name="Name">
<label for="mail" class="form-group" >Email</label>
<input type="email" class="form-control" id="mail" name="Email">
<label for="phone" class="form-group" >Phone</label>
<input type="tel" class="form-control" id="phone" name="Phone">
<button style="padding-left: 4px;padding-right: 3px;">Submit</button>
</form>
</div>
<script>
let submit = document.getElementById('phone').nextElementSibling;
submit.addEventListener('click', (e) => {
e.preventDefault();
let nameInput = document.getElementById('name').value;
let mailInput = document.getElementById('mail').value;
let phoneInput = document.getElementById('phone').value;
let ul = document.createElement('ul');
let obj = {
name : nameInput,
email : mailInput,
phone : phoneInput
}
localStorage.setItem(mailInput,JSON.stringify(obj));
let li = document.createElement('li');
// li.appendChild(document.createTextNode(nameInput));
// li.appendChild(document.createTextNode(' - '));
// li.appendChild(document.createTextNode(mailInput));
// li.appendChild(document.createTextNode(' - '));
// li.appendChild(document.createTextNode(phoneInput));
let el = nameInput + ' - ' + mailInput + ' - '+ phoneInput;
li.appendChild(document.createTextNode(el));
let del = document.createElement('button');
del.className = 'delete';
del.appendChild(document.createTextNode('Delete'));
li.appendChild(del);
ul.appendChild(li);
document.getElementById('list').appendChild(ul);
del.addEventListener('click',(e)=>{
e.preventDefault();
if(e.target.textContent.indexOf('Delete') > -1){
ul.remove(e.target.parentElement);
localStorage.removeItem(mailInput);
}
})
});
</script>
</body>
</html>