Character counter back to default value

Asked

Viewed 49 times

1

Galley,

I have the following problem,

I built this expression in JAVASCRIPT, it captures the amount of characters I typed and subtracted with MAXLENGTH, it works but I’m using JSON (not to post on the page), when I click the Include button the characters I typed it continues from the number I stopped typing, for example, I typed ALEXANDRE, it gets 3991 characters, when clicking Include, it should return to 4000, but it only returns when I start typing, I want the event of the button it already goes back to 4000, follows the 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>
  • Could show the code you use by pressing Include?

  • Alexandre, explains the question better by adding more details and the code of this handset of events.

  • Follow button code: <button type="button" class="btn btn-default" id="btnCasoSucesso">Include success case</button>

1 answer

2


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

ex:

onclick="javascript: $('.caracteres').empty().append('<span>4000 Caracteres</span>')"
  • It worked, thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.