Display character count

Brendan McKenzie asked on August 13, 2014 07:45

Is it possible to add a character count/countdown to editor fields that have a maximum-character limit?

Recent Answers


Joshua Adams answered on August 13, 2014 17:50

Something like this could work:

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on August 13, 2014 17:51

Just include this in a script tag...

$(document).ready(function() {          
  $('ul#controls a').fontSizer();
$('#navigation ul.nav li ul').after('<span class="arrow"></span>');
//Limiting Comments to 150 characters for blog comments

var characters = 150; $(".TextAreaField").keyup(function(){ if($(this).val().length > characters){ $(this).val($(this).val().substr(0, characters)); alert("Comments cannot be more than 149 characters"); } var remaining = characters - $(this).val().length; if(remaining <= 10) { //change the color to red to warn user... $(".TextAreaField").css("color","red"); } else { //change back to original color... $(".TextAreaField").css("color", "black"); } });

});

0 votesVote for this answer Mark as a Correct answer

Brendan McKenzie answered on August 14, 2014 07:20

The problem with that is that it may not always be 150 characters, and there could be multiple fields that have a length restriction.

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on August 14, 2014 15:07

So you attach cssclasses to them and say one of them is a150 another is a250 and another is a500. Then you just add these catches into the code. As long as your css classes are on the fields, then the js should handle the rest if you handle those if statements.

0 votesVote for this answer Mark as a Correct answer

Andy Rokicki answered on January 31, 2018 19:21 (last edited on January 31, 2018 21:34)

Something like this will do it. count including cut and paste + drag.

    <textarea></textarea>
    <span id="characters"><span>

    <script>
     $('textarea').on ("input",updateCount);


function updateCount() {
    var cs = $(this).val().length;
    $('#characters').text(cs);
}
    </script>
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.