Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to count the number of words in any text?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 119
    Comment on it

    We can count the number of words by using split method of javascript.

    What split method does:

    split() - Splits a string into an array of substrings

    Below is an example:-

    <form name=countingWords>
    <textarea rows="12" name="countingWords1 cols="38" wrap="virtual"></textarea><br>
    <input type="button" value="Calculate Words" onClick="quickcount()"> <input type="text" name="countingWords3" size="20">
    </form>
    
    <script type="text/javascript">
    function quickcount(){
    var displaycontent=document. countingWords.countingWords1.value
    displaycontent = displaycontent.split(" ")
    document.countingWords.countingWords3.value= displaycontent.length
    }
    </script>
    

    By using split() method, we separate the text by spaces and then counting the words by length method. Without the help of split method counting the number of words would be a difficult task.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: