There may be one more function that you have to use with length attribute to count words in textbox and textarea that is:
split function with argument as delimiter:
this has the property to split the objects value in array according to given arguments. In the example given below we use split(” “) ,this means split function breaks the string in array as it encounters ” ” or space or delimiter.
Demo:
-
<textarea cols="50" rows="5" name="" id="" onkeyup="getElementById(’count_word’).value = this.value.split(’ ‘).length-1"></textarea>
-
<input type="text" size="10" id="count_word">
Post a Comment