Crash1hd
08-07-2002, 11:42 AM
Ok Somone on here gave me this Javascript (Thankyou)
and it works great except!
if for example you where to use this inside the box
one two three
and then moved outside the box it pops up 3 in a window which is great if you use
one two three
it still pops up six as there is more then 1 space in between two and three also if you use
one two
three
it only sees two even though there is a third word in there
now if I use
one two
three
with the space it sees three and with 2 spaces it sees four!
What I am asking for is really if someone can break down this javascript for me in plain english exactly what everything is doing and how it does it so that I can recreate it to make it work with multiple spaces and enters and or someone too re write it the same way it is now just too incorperate the spaces and enters yet still give an accurate reading :)
Adam
Script Attached below
<script language="JavaScript" type="text/javascript">
<!--
/* Trim leading and trailing spaces from text entries */
function trimtext(txt){
var temptext=txt.replace(/\s*/,'');
ets = temptext.substring(temptext.length-1, temptext.length);
while(ets==" "){
temptext = temptext.substring(0, temptext.length-1);
ets = temptext.substring(temptext.length-1, temptext.length);
}
return temptext;
}
/* Count the number of words in the textarea */
function count_words(x){
var tempstr = trimtext(x.value);
var temparray = tempstr.split(" ");
var arylen = temparray.length;
alert(arylen);
}
// -->
</script>
<textarea rows="5" cols="40" name="textarea" onblur=count_words(this) wrap="VIRTUAL"></textarea>
Again I would Like to thank who ever gave me this script It has been awhile and I am unable to remember so I opoligize :)
and it works great except!
if for example you where to use this inside the box
one two three
and then moved outside the box it pops up 3 in a window which is great if you use
one two three
it still pops up six as there is more then 1 space in between two and three also if you use
one two
three
it only sees two even though there is a third word in there
now if I use
one two
three
with the space it sees three and with 2 spaces it sees four!
What I am asking for is really if someone can break down this javascript for me in plain english exactly what everything is doing and how it does it so that I can recreate it to make it work with multiple spaces and enters and or someone too re write it the same way it is now just too incorperate the spaces and enters yet still give an accurate reading :)
Adam
Script Attached below
<script language="JavaScript" type="text/javascript">
<!--
/* Trim leading and trailing spaces from text entries */
function trimtext(txt){
var temptext=txt.replace(/\s*/,'');
ets = temptext.substring(temptext.length-1, temptext.length);
while(ets==" "){
temptext = temptext.substring(0, temptext.length-1);
ets = temptext.substring(temptext.length-1, temptext.length);
}
return temptext;
}
/* Count the number of words in the textarea */
function count_words(x){
var tempstr = trimtext(x.value);
var temparray = tempstr.split(" ");
var arylen = temparray.length;
alert(arylen);
}
// -->
</script>
<textarea rows="5" cols="40" name="textarea" onblur=count_words(this) wrap="VIRTUAL"></textarea>
Again I would Like to thank who ever gave me this script It has been awhile and I am unable to remember so I opoligize :)