I am using TinyMCE for . My requirement is to limit the character size to 2000 and also to show the remaining characters somewhere below the tool ba
I suggest you execute your code onKeyDown, because on KeyUp the letter is already in the editor.
//peform this action every time a key is pressed
ed.onKeyDown.add(function(ed, e) {
//define local variables
var tinymax, tinylen, htmlcount;
//manually setting our max character limit
tinymax = ed.settings.charLimit;
//grabbing the length of the curent editors content
tinylen = ed.getContent().replace(/(<([^>]+)>)/ig,"").length;
//setting up the text string that will display in the path area
htmlcount = "HTML Character Count: " + tinylen + "/" + tinymax;
//if the user has exceeded the max turn the path bar red.
if (tinylen > tinymax){
// place text string in path bar
if ( $('#max_char_string').size() ){
$('#max_char_string').html( ' ' + htmlcount);
}
else {
$("div#"+ed.id+"_path_row").append(' '+htmlcount+'')
}
// prevent insertion of typed character
e.preventDefault();
e.stopPropagation();
return false;
}