-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
116 lines (94 loc) · 3.04 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Icon Scout 1</title>
<style type="text/css">
.head {
display: flex;
padding: 50px;
justify-content: center;
}
.container {
display: block;
width: 100%;
text-align: center;
}
.menu {
display: table-cell;
position: relative;
width: 33.33%;
padding: 10px 20px;
text-align: center;
}
</style>
</head>
<body>
<div class="head">
<h1>
Task 1
</h1>
</div>
<div class="container">
<div class="menu">
<form id="addForm" onsubmit="event.preventDefault(); addItem();">
<input type="text" name="key" placeholder="key" />
<input type="text" name="value" placeholder="Value" />
<button type="submit">Save</button>
</form>
<div>
<h1 id="addItemOutput">
</h1>
</div>
</div>
<div class="menu">
<form id="searchForm" onsubmit="event.preventDefault(); searchItem();">
<input type="text" name="key" placeholder="key">
<button type="submit">Search</button>
</form>
<h1 id="searchOutput">
</h1>
</div>
<div class="menu">
<form id="deleteForm" onsubmit="event.preventDefault(); deleteItem();">
<input type="text" name="key" placeholder="key">
<button type="submit">Delete</button>
</form>
<h1 id="deleteOutput">
</h1>
</div>
</div>
<script type="text/javascript" src="script1.js"></script>
<script>
function addItem() {
let myKey = document.getElementById("addForm").key.value
let myValue = document.getElementById("addForm").value.value
let addItemOutput = document.getElementById("addItemOutput")
if (!MyStorage.setItem(myKey, myValue)) {
addItemOutput.innerHTML = myKey + ' is already exist';
} else {
addItemOutput.innerHTML = myKey + ' added successfuly';
}
document.getElementById("addForm").reset();
}
function searchItem() {
let myKey = document.getElementById("searchForm").key.value
let searchOutput = MyStorage.getItem(myKey);
if (!searchOutput) {
searchOutput = "Not Found"
}
document.getElementById("searchOutput").innerHTML = searchOutput;
}
function deleteItem() {
let myKey = document.getElementById("deleteForm").key.value
let deleteOutput = document.getElementById("deleteOutput")
if (!MyStorage.removeItem(myKey)) {
deleteOutput.innerHTML = 'Item not exist';
} else {
deleteOutput.innerHTML = 'Deleted successfuly!';
}
document.getElementById("deleteForm").reset();
}
</script>
</body>
</html>