File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed
Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < title > Document</ title >
7+ < script defer src ="script.js "> </ script >
8+ </ head >
9+ < body >
10+ < section >
11+ < h3 > Character limit</ h3 >
12+ < label for ="comment-input "
13+ > Please enter your comment in the text area below
14+ </ label >
15+ < textarea
16+ id ="comment-input "
17+ name ="comment-input "
18+ rows ="5 "
19+ maxlength ="200 "
20+ > </ textarea >
21+ < p id ="character-limit-info "> </ p >
22+ </ section >
23+ </ body >
24+ </ html >
Original file line number Diff line number Diff line change 1+ const textarea = document . querySelector ( "textarea" ) ;
2+ const remainingCharacters = textarea . maxLength - textarea . value . length ;
3+ console . log ( textarea . maxLength ) ;
4+
5+ const charactersLeftP = document . querySelector ( "#character-limit-info" ) ;
6+ charactersLeftP . innerText = `You have ${ remainingCharacters } characters remaining` ;
7+
8+
9+
10+ textarea . addEventListener ( "keyup" ,
11+ ( ) => const remainingCharacters = textarea . maxLength - textarea . value . length ;
12+ const charactersLeftP = document . querySelector ( "#character-limit-info" ) ;
13+ charactersLeftP . innerText = `You have ${ remainingCharacters } characters remaining` ;
14+ console . log ( remainingCharacters ) ;
15+ ) ;
Original file line number Diff line number Diff line change 1+ const textarea = document . querySelector ( "textarea" ) ;
2+
3+ updateCharacterLimit ( ) ;
4+
5+ function updateCharacterLimit ( ) {
6+ const remainingCharacters = textarea . maxLength - textarea . value . length ;
7+ const charactersLeftP = document . querySelector ( "#character-limit-info" ) ;
8+ charactersLeftP . innerText = `You have ${ remainingCharacters } characters remaining` ;
9+ console . log ( remainingCharacters ) ;
10+ }
11+
12+ textarea . addEventListener ( "keyup" , updateCharacterLimit ) ;
You can’t perform that action at this time.
0 commit comments