Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-13-2003, 09:01 AM   PM User | #1
Crash1hd
Regular Coder

 
Join Date: Jul 2002
Location: 51° 03' -78" N -114° 05' 72" W
Posts: 617
Thanks: 0
Thanked 0 Times in 0 Posts
Crash1hd is an unknown quantity at this point
count words in opera!

The following code works fine in all browsers but opera?

Code:
/* 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?

anythoughts?
Crash1hd is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:09 AM.


Advertisement
Log in to turn off these ads.