-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndex.html
More file actions
119 lines (119 loc) · 4.04 KB
/
Index.html
File metadata and controls
119 lines (119 loc) · 4.04 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>To-Do List (Tabular)</title>
<style>
body {
font-family: 'Segoe UI', sans-serif; background-color: #f4f6f8; margin: 0; padding: 40px 15px; display: flex; justify-content: center;
}
.container {
width: 100%; max-width: 800px; background-color: #fff; padding: 25px 30px; border-radius: 10px; box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05);
}
h1 {
text-align: center; color: #2c3e50; margin-bottom: 25px;
}
.input-row {
display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px;
}
.input-row input[type="text"] {
flex: 1; padding: 10px; font-size: 15px; border-radius: 6px; border: 1px solid #ccc;
}
.input-row button { background-color: #3498db; color: white; border: none; padding: 10px 18px; font-weight: bold; font-size: 15px; border-radius: 6px; cursor: pointer;
}
.input-row button:hover {
background-color: #2c80b4;
}
table {
width: 100%; border-collapse: collapse;
}
th, td {
padding: 12px; text-align: left; border-bottom: 1px solid #e0e0e0;
}
th {
background-color: #f0f0f0; color: #333;
}
td .delete-btn {
background-color: #e74c3c; border: none; color: white; padding: 6px 10px; font-size: 14px; border-radius: 4px; cursor: pointer;
}
td .delete-btn:hover {
background-color: #c0392b;
}
td.completed {
text-decoration: line-through; color: #888;
}
@media (max-width: 600px) {
.input-row {
flex-direction: column;
}
th, td {
font-size: 14px;
}
}
</style>
</head>
<body>
<div class="container">
<h1> My To-Do Table</h1>
<div class="input-row">
<input type="text" id="taskInput" placeholder="Enter a task..." />
<button onclick="addTask()">Add Task</button>
</div>
<table>
<thead>
<tr>
<th>Task Name</th>
<th>Completed</th>
<th>Date Added</th>
<th>Action</th>
</tr>
</thead>
<tbody id="taskTable">
<!-- Tasks will appear here -->
</tbody>
</table>
</div>
<script>
function addTask() {
const taskInput = document.getElementById("taskInput");
const taskText = taskInput.value.trim();
if (taskText === "") {
alert("Please enter a task.");
return;
}
const table = document.getElementById("taskTable");
const row = table.insertRow();
const taskCell = row.insertCell(0);
const completeCell = row.insertCell(1);
const dateCell = row.insertCell(2);
const deleteCell = row.insertCell(3);
taskCell.textContent = taskText;
const checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.addEventListener("change", function () {
if (checkbox.checked) {
taskCell.classList.add("completed");
}
else {
taskCell.classList.remove("completed");
}
});
completeCell.appendChild(checkbox); // Auto-date
const today = new Date();
const formattedDate = today.toLocaleDateString("en-GB", {
day: "2-digit", month: "short", year: "numeric"
});
dateCell.textContent = formattedDate; // Delete button
const deleteBtn = document.createElement("button");
deleteBtn.className = "delete-btn";
deleteBtn.textContent = "Delete";
deleteBtn.onclick = function () {
row.remove();
};
deleteCell.appendChild(deleteBtn);
taskInput.value = "";
}
</script>
</body>
</html>