word count




JavaScript Source Code 3000: Forms: Word Count







































Word Count







Finally, an easy way to count the number of words that are entered into a form!














JavaScript Source Code 3000: Forms: Word Count
Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Command-s). The script is yours!!!





    





<!-- TWO STEPS TO INSTALL WORD COUNT:

1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Shawn Seley -->

<! >
<! >

<!-- Begin
function CountWords (this_field, alertWords, alertChars) {
if (alertWords == null) {
alertWords = true;
}
if (alertChars == null) {
alertChars = false;
}
var fullStr = this_field.value;
var charCount = fullStr.length;
var rExp = /[^A-Za-z0-9]/gi;
var spacesStr = fullStr.replace(rExp, " ");
var cleanedStr = spacesStr + " ";
do {
var old_str = cleanedStr;
cleanedStr = cleanedStr.replace(" ", " ");
} while(old_str != cleanedStr);
var splitString = cleanedStr.split(" ");
var wordCount = splitString.length -1;
if (fullStr.length <1) {
wordCount = 0;
}
if (wordCount == 1) {
wordOrWords = " word";
}
else {
wordOrWords = " words";
}
if (charCount == 1) {
charOrChars = " character";
} else {
charOrChars = " characters";
}
if (alertWords & alertChars) {
alert ("Word Count:\n" + " " + wordCount + wordOrWords + "\n" + " " + charCount + charOrChars);
}
else {
if (alertWords) {
alert ("Word Count: " + wordCount + wordOrWords);
}
else {
if (alertChars) {
alert ("Character Count: " + charCount + charOrChars);
}
}
}
return wordCount;
}
// End -->
</script>

</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<form>
<textarea cols=40 rows=5 name=x>
</textarea>
<br>
<input type=button value="Count Words" OnClick ="CountWords(this.form.x, true, true);">
</form>



<!-- Script Size: 1.94 KB -->











Wyszukiwarka

Podobne podstrony:
function str word count
Word 2013 Keyboard Shortcuts
Christmas word challenges
function mhash count
word chop witch brew
word
zadania word
TEMAT 2 MiTBNB word
The L Word [1x12] Locked Up (XviD asd)
count if
Word
KURS WORD 2007
Neu Microsoft Word Dokument
Gra planszowa Super word racer
MS Word dla opornych
word

więcej podobnych podstron