-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompositeToDo.html
More file actions
101 lines (90 loc) · 2.72 KB
/
compositeToDo.html
File metadata and controls
101 lines (90 loc) · 2.72 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>To Do V2</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">
<div class="content">
<div class="row">
<label for="input"></label>
<input type="text" id="input">
<button id="submit">Enter</button>
</div>
<table>
<thead>
<tr>
<th>
Incomplete
</th>
<th>
</th>
</tr>
</thead>
<tbody id="incomplete">
</tbody>
</table>
<p>--------------------------</p>
<table>
<thead>
<tr>
<th>
Complete
</th>
<th>
</th>
</tr>
</thead>
<tbody id="complete">
</tbody>
</table>
</div>
</div>
</body>
<script>
const item = document.querySelector('input');
const submitButton = document.getElementById('submit');
const incomplete = document.getElementById('incomplete');
const complete = document.getElementById('complete');
submitButton.addEventListener('click', function () {
let toDoItem = item.value;
addItemToTable(toDoItem, incomplete);
item.value = "";
});
function addItemToTable(item, table){
let tableName = table.id;
// console.log(tableName);
let newRow = document.createElement('tr');
let descriptionTag = document.createElement('td');
descriptionTag.textContent = item;
newRow.appendChild(descriptionTag);
let actionTag = document.createElement('td');
let action = document.createElement('button');
if (tableName === 'incomplete'){
action.textContent = "Mark Complete";
// console.log('MARK COMPLETE')
} else if (tableName === 'complete') {
action.textContent = "Mark Incomplete";
// console.log('MARK INCOMPLETE')
} else {
console.log('FAILED');
}
action.addEventListener('click', function(){
newRow.remove();
if (tableName === 'incomplete'){
addItemToTable(item, complete)
} else if (tableName === 'complete') {
addItemToTable(item, incomplete)
}
});
actionTag.appendChild(action);
newRow.appendChild(actionTag);
if (tableName === 'incomplete'){
incomplete.appendChild(newRow);
} else if (tableName === 'complete') {
complete.appendChild(newRow);
}
}
</script>