Counting words in a textarea using javascript

In this javascript tutorial we will learn how to count the number of words entered in a textarea using javascript. Let's have a look over below mentioned code that demonstrates how to count the words entered in a textarea using javascript.

<script language="javascript" type="text/javascript">

function counting_words(txt_Name)
{

var number_of_words;
number_of_words=txt_Name.value.split(" ");

alert("Textbox has "+number_of_words.length+" words");

return false;

}

Now here's the code that will made textarea in your webpage.

<form name="form1">
<textarea name="details"> </textarea>
<input type="submit" value="Check" onclick="return counting_words(document.form1.details)"></form>

Now when you will entered the words in textarea and then press submit button then an alert will come that will show you how many words you have entered in the textrea.

So this is the way to count words in a textarea using javascript.

0 comments: