-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (62 loc) · 2.73 KB
/
index.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
// Delay function
function delay(time) {
return new Promise(resolve => setTimeout(resolve, time));
}
let mouseInButton = false
// Hover part to give the button a color
document.getElementById("submitButton").addEventListener("mouseenter", async function() {
mouseInButton = true
const button = document.getElementById("submitButton");
await delay(900);
if (mouseInButton) {
button.setAttribute("style","background-color: rgb(250, 187, 188)")
}
})
// Hover away to remove the color
document.getElementById("submitButton").addEventListener("mouseleave", async function() {
mouseInButton = false
const button = document.getElementById("submitButton");
button.setAttribute("style","background-color: white")
})
//===================================================================================================
const taskTable = document.getElementById("taskTable");
let numberOfCreatedRows = 0
let numberOfTotalRows = 0
document.getElementById("submitButton").addEventListener("click", async function() {
if (document.getElementById("taskNameBox").value.length <= 0 || document.getElementById("taskDescBox").value.length <= 0) {
const taskNameBox = document.getElementById("taskNameBox")
const taskDescBox = document.getElementById("taskDescBox")
taskNameBox.setAttribute("placeholder","Value required here!")
taskDescBox.setAttribute("placeholder","Value required here!")
await delay(1000);
taskNameBox.setAttribute("placeholder","Type task name here")
taskDescBox.setAttribute("placeholder","Type task description here")
} else {
numberOfCreatedRows++;
numberOfTotalRows++;
const newRow = document.createElement('tr')
newRow.setAttribute("id",`rowID-${numberOfCreatedRows}-0`)
newRow.innerHTML = `
<th>${document.getElementById("taskNameBox").value}</th>
<th>${document.getElementById("taskDescBox").value}</th>
<th>${document.getElementById("taskDateBox").value}</th>
<th><button onclick="removeRowFunc(${numberOfCreatedRows})" class="removebutton tnrFormat">Remove</button></th>
`
taskTable.append(newRow)
}
if (numberOfTotalRows > 0) {
const taskTableVisibility = document.getElementById("taskList")
taskTableVisibility.setAttribute("style","visibility: visible")
}
})
function removeRowFunc(rowIndex) {
numberOfTotalRows--;
const deleteElement = document.getElementById(`rowID-${rowIndex}-0`)
for (let i = 0; i<4; i++) {
deleteElement.remove()
}
if (numberOfTotalRows == 0) {
const taskTableVisibility = document.getElementById("taskList")
taskTableVisibility.setAttribute("style","visibility: hidden")
}
}