0
I want to improve this function, because when you break the line, it doesn’t count the characters properly:
$(function(){
$("#maxlength").keyup(function(event){
var target = $("#content-countdown");
var max = target.attr('title');
var len = parseInt($(this).val().length);
var remain = max - len;
if (len > max) {
var val = $(this).val();
$(this).val(val.substr(0, max));
remain = 0;
}
target.html(remain);
});
});
HTML
<textarea name="body" maxlength="100" id="maxlength" placeholder="O que está acontecendo?"></textarea>
<input type="submit" name="send" value="Post">
<span id="content-countdown" title="100">100</span>
When he breaks the line he doesn’t count or count ? why when he breaks the line he is giving spaces these spaces are counted as characters
– Gabriel Rodrigues
when I break the line to the maximum it only counts 50 characters, but can’t type anymore.
– Jonas Alves
I did a test here and I didn’t find this problem... http://jsfiddle.net/filadown/tv0rrv0r/
– Gabriel Rodrigues
In the secure textarea enter until it stops, appears 50, I want it to stay 0.
– Jonas Alves