How to count WORDS in JavaScript ? OR How to make word counter in JavaScript ?

Description:- Few days before I made and upload character counter which is right here ( https://webtechball.wordpress.com/2015/02/25/how-to-make-fully-responsive-character-counter-through-javascript/ ) and today  Through this example you can easily make your own word counter not the character counter. In character counter user can easily know how many character he have written, but through word counter one can easily find out how many words he have written.

<!DOCTYPE HTML>
<head>
<title>Word counter</title>
<style>
#aaa{border:hidden;}
</style>
</head>
<body>
<textarea name="comment" onkeyup="wordcount(this.value)" rows="5" cols="50"></textarea> <br/>
</body>
</html>

<script>
document.write("<input type=text id=aaa readonly/>");
function wordcount(type) 
{
var words = type.split(/\s/);
var bbb = words.length;
var ccc = document.getElementById('aaa');
ccc.value = bbb;
}
</script>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s