File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ <h1>Too Doo List</h1>
2828 < div id ="main " role ="main " class ="page-content ">
2929 < div class ="todo-form-wrapper ">
3030 < form id ="todo-form " class ="todo-form ">
31+ < div id ="error "> </ div >
3132 < input type ="text " id ="todo-add-new " class ="todo-input " placeholder ="Add item " />
3233 < button id ="btn-submit " type ="submit "> Add to do</ button >
3334 </ form >
Original file line number Diff line number Diff line change @@ -28,15 +28,25 @@ document.getElementById('btn-submit').addEventListener(
2828 'click' ,
2929 function ( event ) {
3030 event . preventDefault ( ) ;
31- addToDo ( ) ;
31+ if ( ! newToDo . value ) {
32+ document . getElementById ( 'error' ) . innerHTML = "Please enter a value!" ;
33+ } else {
34+ addToDo ( ) ;
35+ }
3236 } ,
3337 false
3438) ;
3539
3640newToDo . onkeydown = function ( event ) {
3741 if ( event . keyCode == 13 ) {
3842 event . preventDefault ( ) ;
39- addToDo ( ) ;
43+
44+ if ( ! newToDo . value ) {
45+ document . getElementById ( 'error' ) . innerHTML ( "Please enter a value!" ) ;
46+ } else {
47+ addToDo ( ) ;
48+ }
49+
4050 return false ;
4151 }
4252} ;
You can’t perform that action at this time.
0 commit comments