Sunday, May 13, 2007

Count Words Using JavaScript

To use this script, place the following code in the document head:

function countWords(){
document.form1.wordcount.value = document.form1.inputString.value.split(' ').length;
}

Place the following code in the document body:









You can adapt this script to count words is whichever way you like. The important part is inputString.value.split(' ').length — this counts the spaces.

No comments: