Search This Blog
Popular Posts
- List of KeyAscii in VB6.0
- List of VB Keycode in Visual Basic 6.0
- Enable and Disable Button VB6 code
- Check valid Email Address in PHP code
- Clear Textbox when Onclick HTML Javascript code
- Get the Filename and the extension of Filename Visual Basic 6.0
- Disable Right-Click of Website - HTML code
- Latest Plate Number with barcode in the Philippines
Count how many characters in Text Area in HTML code
In HTML code
<form name="count_form" method="post" action="">
<textarea name="desc" cols="40" rows="7" id="desc"
onKeyDown="CountWordsLeft(count_form, document.count_form.desc, document.count_form.count,100);"
onKeyUp="CountWordsLeft(count_form, document.count_form.desc, document.count_form.count,100);"
onPaste="CountWordsLeft(count_form, document.count_form.desc, document.count_form.count,100);">
</textarea>
<input readonly name="count" type="text" size="5" value="100">
</form>
--- In Javascript
function CountWordsLeft(myForm, field, count, no_words) {
var text=field.value + " ";
if(no_words>0)
{
var iwhitespace = /^[^A-Za-z0-9]+/gi; // remove initial whitespace
var left_trimmedStr = text.replace(iwhitespace, "");
var na = rExp = /[^A-Za-z0-9]+/gi; // non alphanumeric characters
var cleanedStr = left_trimmedStr.replace(na, " ");
var splitString = cleanedStr.split(" ");
var word_count = splitString.length -1;
count.value=no_words-word_count;
}
}