-1

this is my code

<h3>Comment</h3>
<textarea name="comment" id="comment" placeholder="Your Comment" maxlength="300" required/></textarea>

And I want to display how many characters left like in twitter with JavaScript only ! is there some way ?
I know nothing in javascript !

Bouzaid
  • 66
  • 8

1 Answers1

1

var letterLimit = 150; 
var textarea = document.getElementById("comment");

document.getElementById("lettersCount").innerHTML  = letterLimit;

textarea.addEventListener('input', function() {
  document.getElementById("lettersCount").innerHTML = letterLimit - textarea.value.length;
}, false);
<h3>Comment</h3>
<textarea name="comment" id="comment" placeholder="Your Comment" maxlength="300" required/></textarea>
<div id="lettersCount"></div>
Egor Litvinchuk
  • 1,800
  • 2
  • 14
  • 15