Repository navigation
Expand file tree
/
Copy pathtodo.html
More file actions
171 lines (150 loc) · 4.31 KB
/
Copy pathtodo.html
File metadata and controls
171 lines (150 loc) · 4.31 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Numbered To-Do List</title>
<style>
body {
margin: 0;
font-family: 'Segoe UI', sans-serif;
background: linear-gradient(to bottom right, #000, #222);
color: white;
display: flex;
flex-direction: column;
align-items: center;
padding: 30px;
height: 100vh;
}
.container {
background: rgba(255, 255, 255, 0.05);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 20px;
padding: 30px;
width: 95%;
max-width: 500px;
box-shadow: 0 0 20px #0f0;
}
h1 {
text-align: center;
margin-bottom: 20px;
color: #0f0;
}
input[type="text"], input[type="number"] {
width: 100%;
padding: 10px;
margin: 10px 0;
border: none;
border-radius: 8px;
font-size: 16px;
outline: none;
}
button {
padding: 10px 20px;
margin: 8px 0;
font-size: 16px;
border: none;
border-radius: 8px;
cursor: pointer;
transition: 0.3s;
}
button:hover {
transform: scale(1.03);
}
.btn-add { background: #4caf50; color: white; width: 100%; }
.btn-edit { background: #2196f3; color: white; width: 100%; }
.btn-toggle { background: #9c27b0; color: white; width: 100%; }
.btn-delete { background: #f44336; color: white; width: 100%; }
ul {
list-style-type: none;
padding: 0;
max-height: 250px;
overflow-y: auto;
margin: 15px 0;
}
li {
padding: 8px 10px;
border-bottom: 1px solid #444;
font-size: 17px;
}
.input-row {
display: flex;
gap: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>📝 Numbered To-Do List</h1>
<label for="taskInput">New Task:</label>
<input type="text" id="taskInput" placeholder="Enter a task...">
<button class="btn-add" onclick="addTask()">Add Task</button>
<h3>Your Tasks:</h3>
<ul id="taskList"></ul>
<label for="taskNumber">Enter Task Number:</label>
<input type="number" id="taskNumber" placeholder="e.g. 1">
<button class="btn-edit" onclick="editTask()">✏️ Edit Task</button>
<button class="btn-toggle" onclick="toggleDone()">✅ Mark Done/Undone</button>
<button class="btn-delete" onclick="deleteTask()">🗑️ Delete Task</button>
</div>
<script>
let tasks = [];
function updateList() {
const list = document.getElementById('taskList');
list.innerHTML = '';
tasks.forEach((task, i) => {
const status = task.done ? "✔️" : "❌";
const li = document.createElement('li');
li.textContent = `${i + 1}. ${status} ${task.title}`;
list.appendChild(li);
});
}
function addTask() {
const input = document.getElementById('taskInput');
const title = input.value.trim();
if (!title) {
alert("Please enter a task.");
return;
}
tasks.push({ title, done: false });
input.value = '';
updateList();
}
function getTaskIndex() {
const indexInput = document.getElementById('taskNumber').value;
const index = parseInt(indexInput) - 1;
if (isNaN(index) || index < 0 || index >= tasks.length) {
alert("Please enter a valid task number.");
return null;
}
return index;
}
function editTask() {
const index = getTaskIndex();
if (index !== null) {
const oldTitle = tasks[index].title;
const newTitle = prompt("Edit task:", oldTitle);
if (newTitle !== null && newTitle.trim() !== "") {
tasks[index].title = newTitle.trim();
updateList();
}
}
}
function toggleDone() {
const index = getTaskIndex();
if (index !== null) {
tasks[index].done = !tasks[index].done;
updateList();
}
}
function deleteTask() {
const index = getTaskIndex();
if (index !== null) {
tasks.splice(index, 1);
document.getElementById('taskNumber').value = '';
updateList();
}
}
</script>
</body>
</html>