Skip to content

Commit bdb553e

Browse files
committed
Fix: prevent adding empty todo items
1 parent f9755bc commit bdb553e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

20-SessionStorage-TodoList/app.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ function get_todos() {
1010

1111
function add() {
1212
var task = document.getElementById("task").value.trim(); // remove extra spaces
13+
var alertMessage = document.getElementById("alert");
14+
alertMessage.style.display = "none"; // hiding alert message initially
1315

1416
if (task === "") {
15-
alert("Please enter a task before adding!");
17+
alertMessage.style.display = "block"; // show alert if task is empty
1618
return false; // stop if empty
1719
}
1820

20-SessionStorage-TodoList/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<body>
1111
<div id="wrapper">
1212
<h1>Todo List</h1>
13+
<p id="alert">Task field is empty</p>
1314
<input type="" id="task" /><button id="add">Add Task</button>
1415
<div id="todos"></div>
1516
</div>

20-SessionStorage-TodoList/style.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,10 @@ ul {
5353
h1 {
5454
margin-top: 30px;
5555
}
56+
57+
#alert {
58+
display: none;
59+
color: red;
60+
font-weight: bold;
61+
margin-top: 10px;
62+
}

0 commit comments

Comments
 (0)