GrimFandango
10-04-2008, 09:12 PM
hello
i'm a beginner please help me
i'm trying to build a page with a text area that underneath it there's
a line that updates while typing -how many words the user wrote.
i've allready did a line with a characters counter :
<HTML>
<HEAD>
<script type="text/javascript">
var yht= "You have Typed ";
function defineCharacters()
{
var innerText = document.getElementById("textField").value;
var charLength = innerText.length;
var lineOneInfo = yht+charLength+" characters";
document.getElementById("firstLine").innerHTML=lineOneInfo;
}
</script>
</HEAD>
<BODY>
<h1> Exercise number 6: </h1>
<textarea rows="8" cols="70" id="textField" align="ltr" onkeydown="return defineCharacters()"></textarea>
<h3 id="firstLine" onkeydown="defineCharacters()">
</h3>
<h3 id="secondLine">
</h3>
<h3 id="ThirdLine">
</h3>
</BODY>
</HTML>
I don't know how to make it count the words.. like: "I love hummus" = 3 words.
I thougth to make it define the words with RegEx : /^\s*\[A-Za-z]+\s+/;
but I don't know what to do with it
i'm a beginner please help me
i'm trying to build a page with a text area that underneath it there's
a line that updates while typing -how many words the user wrote.
i've allready did a line with a characters counter :
<HTML>
<HEAD>
<script type="text/javascript">
var yht= "You have Typed ";
function defineCharacters()
{
var innerText = document.getElementById("textField").value;
var charLength = innerText.length;
var lineOneInfo = yht+charLength+" characters";
document.getElementById("firstLine").innerHTML=lineOneInfo;
}
</script>
</HEAD>
<BODY>
<h1> Exercise number 6: </h1>
<textarea rows="8" cols="70" id="textField" align="ltr" onkeydown="return defineCharacters()"></textarea>
<h3 id="firstLine" onkeydown="defineCharacters()">
</h3>
<h3 id="secondLine">
</h3>
<h3 id="ThirdLine">
</h3>
</BODY>
</HTML>
I don't know how to make it count the words.. like: "I love hummus" = 3 words.
I thougth to make it define the words with RegEx : /^\s*\[A-Za-z]+\s+/;
but I don't know what to do with it