Are you looking to build a script like twitter to show your users how many characters they have remaining to write? If your answer is yes, then keep a close eye in this tutorial. In this tutorial, I will explain how to count a character in textarea using jQuery. This is a quick tutorial about jQuery.
It is very useful as we need most of the time to create a textarea which will count the entered character by the user in the real web application development.
Please make sure you have included the below jQuery file in your web page where you want to implement the character count functionality for your textarea.
Use below code to create textarea characters count in your web applications. Copy paste below jQuery code in your page before head tag closed.
var text_max = 250;
$('#textarea_feedback').html(text_max + ' characters remaining');
var text_length = $('#textarea').val().length;
var text_remaining = text_max - text_length;
$('#textarea_feedback').html(text_remaining + ' characters remaining');
Use below code in your application where you want to use character counter in textarea.
<label>Type you text</label>
<textarea id="textarea" maxlength="250" onkeyup="countChar(this)" class="form-control" rows="3"></textarea>
Prem Tiwari is the founder of FreeWebMentor.com and also a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies. View all posts by Prem Tiwari