-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
67 lines (51 loc) · 2.32 KB
/
script.js
File metadata and controls
67 lines (51 loc) · 2.32 KB
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
document.addEventListener("DOMContentLoaded", function() {
loadPasswordEntries();
const passwordForm = document.getElementById("passwordForm");
passwordForm.addEventListener("submit", function(event) {
event.preventDefault();
savePasswordEntry();
});
// Add an event listener for dynamically created delete buttons
document.getElementById("passwordTable").addEventListener("click", function(event) {
if (event.target.classList.contains("delete-btn")) {
deletePasswordEntry(event.target);
}
});
});
function loadPasswordEntries() {
const passwordTable = document.getElementById("passwordTable");
passwordTable.innerHTML = "";
const passwordDetails = JSON.parse(localStorage.getItem("passwordDetail")) || [];
passwordDetails.forEach(function(entry, index) {
const row = document.createElement("tr");
row.innerHTML = `
<td>${entry.Website}</td>
<td>${entry.Username}</td>
<td>${entry.Password}</td>
<td><button class="delete-btn" data-index="${index}">Delete</button></td>
`;
passwordTable.appendChild(row);
});
}
function savePasswordEntry() {
const Website = document.getElementById("Website").value;
const Username = document.getElementById("Username").value;
const password = document.getElementById("password").value;
const passwordDetails = JSON.parse(localStorage.getItem("passwordDetail")) || [];
passwordDetails.push({ Website, Username, Password: password });
localStorage.setItem("passwordDetail", JSON.stringify(passwordDetails));
loadPasswordEntries();
document.getElementById("Website").value = "";
document.getElementById("Username").value = "";
document.getElementById("password").value = "";
}
function deletePasswordEntry(deleteButton) {
const index = deleteButton.getAttribute("data-index");
const passwordDetails = JSON.parse(localStorage.getItem("passwordDetail")) || [];
if (index !== null && index >= 0 && index < passwordDetails.length) {
passwordDetails.splice(index, 1);
localStorage.setItem("passwordDetail", JSON.stringify(passwordDetails));
loadPasswordEntries();
}
alert("Confirm to delete Password!");
}