Character counter returning to the default value

1

Galera,

I have the following problem,

I put this expression in JAVASCRIPT, it captures the amount of characters I typed and subtracts with MAXLENGTH, it works however I am using JSON (not to post on the page), when I click the Add characters button it continues number that I stopped typing, for example, I typed ALEXANDRE, it is 3991 characters, when I click Add, it should return to 4000, but it only returns when I start typing, I want it to return to 4000 in the button event, code ...

JAVASCRIPT:

$(document).on("input", "#DescricaoCadastro", function () {
    var limite = 4000;
    var caracteresDigitados = $(this).val().length;
    var caracteresRestantes = limite - caracteresDigitados;
    $(".caracteres").text(caracteresRestantes + " Caracteres");

});

HTML:

<label class="control-label col-sm-11 stf-alignright caracteres"><span>4000 Caracteres</span></label>
    
asked by anonymous 19.11.2015 / 18:35

1 answer

2

puts an onclick on the button so when it is clicked, the counter changes to 4000.

ex:

onclick="javascript: $('.caracteres').empty().append('<span>4000 Caracteres</span>')"
    
19.11.2015 / 20:35