File tree Expand file tree Collapse file tree 3 files changed +18
-2
lines changed
20-SessionStorage-TodoList Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -9,17 +9,25 @@ function get_todos() {
99}
1010
1111function add ( ) {
12- var task = document . getElementById ( "task" ) . value ;
12+ 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
15+
16+ if ( task === "" ) {
17+ alertMessage . style . display = "block" ; // show alert if task is empty
18+ return false ; // stop if empty
19+ }
1320
1421 var todos = get_todos ( ) ;
1522 todos . push ( task ) ;
1623 localStorage . setItem ( "todo" , JSON . stringify ( todos ) ) ;
1724
1825 show ( ) ;
1926 clearDefault ( ) ;
20- return false ; //avoids any futher action with click event
27+ return false ; // avoids any further action with click event
2128}
2229
30+
2331//clear the task value from input box
2432function clearDefault ( ) {
2533 document . getElementById ( "task" ) . value = "" ;
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 5353h1 {
5454 margin-top : 30px ;
5555}
56+
57+ # alert {
58+ display : none;
59+ color : red;
60+ font-weight : bold;
61+ margin-top : 10px ;
62+ }
You can’t perform that action at this time.
0 commit comments