I have a text area field where i need to provide information about the word count when the user enters some text in the field. Length of the field is supposed to be 500 Characters.
Initialy it must show
min characters:100 | 0 of 500 // 0 of 500 must be in red color
and once the user enters come character need to update the count as well. Once the user reaches the count say the min character 100, i need to display
min characters:100 | 100 of 500 // 100 of 500 must be in green color.
How can i do this?? is there any plugin for the same??? let me know your thoughts on this.
<textarea id="field" onkeyup="countChar(this)"></textarea> function countChar(val){ var len = val. value. length; if (len >= 500) { val. value = val.
We can find the length of the string by the jQuery . length property. The length property contains the number of elements in the jQuery object. Thus it can be used to get or find out the number of characters in a string.
Note − By default, we can enter data in a textarea upto 5,24,288 characters. In some cases, there is a need of putting a limit on the size of characters that can be typed in a textarea. So in that case, we can use maxlength attribute to control the number of characters entered in a textarea.
Simplest way to count:
var count = $("#your_textarea").val().length;
$("#your-text-area").on('keyup', function(event) {
var currentString = $("#your-text-area").val()
$("Your Div").html(currentString.length);
if (currentString.length <= 500 ) { /*or whatever your number is*/
//do some css with your div
} else {
//do some different stuff with your div
}
});
http://api.jquery.com/bind/
Try to use this plugin feature
jquery-character-counter from jqeasy.com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With