-
Notifications
You must be signed in to change notification settings - Fork 0
/
addharam.js
53 lines (43 loc) · 1.46 KB
/
addharam.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
// Load haramlist from localStorage or create an empty object
var haramlist = JSON.parse(localStorage.getItem("haramlist")) || {};
// Add existing data to the table
for (var name in haramlist) {
var value = haramlist[name];
addRow(name, value);
}
document.getElementById('addRow').addEventListener("click", function() {
var name = document.getElementById('title').value
var value = document.getElementById('background-audio').value
// Add data to object
haramlist[name] = value;
// Add row to table
addRow(name, value);
// Save updated data to localStorage
saveData();
});
function addRow(name, value) {
// Add row to table
var table = document.getElementById("myTable");
var row = table.insertRow(-1);
var nameCell = row.insertCell(0);
var valueCell = row.insertCell(1);
var deleteCell = row.insertCell(2);
nameCell.innerHTML = name;
valueCell.innerHTML = value;
var deleteButton = document.createElement("button");
deleteButton.textContent = "Delete";
deleteButton.addEventListener("click", function() {
var row = this.parentNode.parentNode;
row.parentNode.removeChild(row);
delete haramlist[name];
saveData();
});
deleteCell.appendChild(deleteButton);
saveData()
}
function saveData() {
// Convert data object to JSON
var jsonData = JSON.stringify(haramlist);
// Save JSON data to localStorage
localStorage.setItem("haramlist", jsonData);
}