Hey folks,
I somehow managed to create a script that locks up Mozilla (1.3)
tight. Here's the culprit, perhaps y'all can provide some insight
into what the trouble is. (This script was cobbled together from
several different word-count routines I found on the web, none of
which worked correctly in all cases.)
function trim(data)
{
i=0;
while (/\s/.test(data.char At(i)))
{data=data.subs tring(i,data.le ngth);}
i=data.length;
while (/\s/.test(data.char At(i))) {data=data.subs tring(1,i);}
return data;
}
function countWords()
{
input=document. forms[0].elements[0].value;
input=trim(inpu t);
wordList=input. split(/\s+/g);
output=wordList .length;
return output;
}
activated via a button: onClick="alert( countWords())"
Thanks for any help,
--David
I somehow managed to create a script that locks up Mozilla (1.3)
tight. Here's the culprit, perhaps y'all can provide some insight
into what the trouble is. (This script was cobbled together from
several different word-count routines I found on the web, none of
which worked correctly in all cases.)
function trim(data)
{
i=0;
while (/\s/.test(data.char At(i)))
{data=data.subs tring(i,data.le ngth);}
i=data.length;
while (/\s/.test(data.char At(i))) {data=data.subs tring(1,i);}
return data;
}
function countWords()
{
input=document. forms[0].elements[0].value;
input=trim(inpu t);
wordList=input. split(/\s+/g);
output=wordList .length;
return output;
}
activated via a button: onClick="alert( countWords())"
Thanks for any help,
--David
Comment