Count Characters in Textarea using JavaScript | Onkeyup Function
HTML-код
- Опубликовано: 1 окт 2024
- In this video tutorial, you will learn how to count characters in textarea using javascript.
Onkeyup function is used on textarea
Whenever a key is pressed , javascript function is called and length of textarea value is counted.
then count is checked with max no of characters, if length is smaller then you can write more letters
else only upto max characters is written and textrea value substring is passed in value
textarea
textarea class="form-control" id="description" style="height: 400px;" placeholder="Please write 100 words description" onkeyup="charCount(this)" /textarea
script
function charCount(textarea){
var max=100;
var length=textarea.value.length;
if( length greater than max)
{
textarea.value=textarea.value.substring(0,100);
}
else{
$('#textcount').text(max - length);
}
Count Characters in Textarea using JavaScript | Onkeyup Function
Stop user from entering maximun characters.
#javascript #knowledgethrusters
How to count only characters without counting line breaks or
Thanks, this is really useful.
waw! Thankyou so much!
Thanks
Thanks 😊