6
I have this text box to be validated, should inform the amount of characters remaining and show these characters remaining in span, could help me?
<div class="novaLinha">
<div>
<label for="txtVoce">Faleme sobre você:</label>
</div>
<div>
<textarea id="txtVoce" name="txtVoce" cols="40" rows="10"></textarea>
<p><span id="carResTxtVoce" style="font-weight: bold;">400</span> caracteres restantes</p>
<p class="aviso" id="avisoTxtVoce" style="display:none;">Este campo não pode ficar vazio!</p>
</div>
</div>
+1, I believe Voce should add a
maxlength="400"
in the textarea to avoid typing more characters and cutting them, it is more natural.– Gabriel Rodrigues
@Gabrielrodrigues thank you. Regarding your suggestion this is already there. On the line
this.value = this.value.slice(0, limite);
– Sergio
html maxlength intercepts faster than javascript keyup, so when it is going to type the 400 character the letter will not appear and then it will be cut.
– Gabriel Rodrigues
@Gabrielrodrigues thought you were suggesting via Javascript. In HTML is much better than via Javascript. I added this in the reply, thank you.
– Sergio
da para deixar mais xuto assim:https://jsfiddle.net/bsy6m8b7/1/
– Gabriel Rodrigues
@Exact Gabrielrodrigues, if the limit is set in HTML is fine.
– Sergio