View Full Version : count words in opera!

06-13-2003, 09:01 AM
The following code works fine in all browsers but opera?

/* 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(/\s+/);
var arylen = temparray.length;
alert(arylen + " Words Total");

Not Sure why but when you use this in a text box and put the following in the box "more then one word here" and click the button to check it you get 1 word?

but if you put the following in the box " /\s+// " and click the button to check it you get 2 words?


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum