navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
FrontPage Alternative
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

 

Counting Words

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> General Web Development >> Counting Words
Page: [1]
 
FrogMan

 

Posts: 108
From: Lewiston, Idaho US
Status: offline

 
Counting Words - 4/3/2001 20:15:00   
Okay, I am getting a little frustrated now.
I have been messing around with a site form inwhich I need to count the number of words that a visitor enters into a scolling text box (I have wrap=virtual ON). Thus far I have not found or been able to figure out how to count the "words". Once I know how many words there are in the text box I will set a range to calculate on the number of words a response; ie, if 10 words multlipy by 1, if 15 words multiply by 1 and add 3, if more than 15 words, multiply by .5.
Any Ideas?

------------------
Everyday is a brighter day, just a few are dimm.

Rian

 

Posts: 1960
From: Lincoln, Nebraska USA
Status: offline

 
RE: Counting Words - 4/3/2001 20:10:00   
How about counting characters?
***************************************

<body onLoad="document.myForm.smsInput.focus()">

<form NAME="myForm">

<input type="text" name="count" value="160" size="3" onFocus="this.blur" readonly>

<br>

<textarea rows="5" cols="50" name="smsInput" wrap
onKeyUp="
val = this.value;
if (val.length > 160) {
alert('Sorry, you are over the limit of 160 characters');
this.value = val.substring(0,160);
smsInput.focus()
}
this.form.count.value=160-parseInt(this.value.length);
"></textarea>

</form>

</body>


************************************


Rian

------------------
Webmaster
SR Web Creators
http://www.srwebcreators.com
_ _________________ _
"Press ENTER once to quit or twice to save changes..."
_ ________________ _


(in reply to FrogMan)
FrogMan

 

Posts: 108
From: Lewiston, Idaho US
Status: offline

 
RE: Counting Words - 4/3/2001 20:28:00   
Thanks Rian.
This may just work and it gives me another thought. Counting the "Spaces" and adding "1" would work. In this manner it ends up with the same results. The problem I see with "just" counting characters, is the formula after the count is based on words. Think of a News paper "obituary". They charge based on the number of words, not characters.
But let me try your formula out and see what jells.
Thanks again.

(in reply to FrogMan)
Mojo

 

Posts: 2441
From: Chicago
Status: offline

 
RE: Counting Words - 4/3/2001 23:43:00   
FrogMan,

I just wrote this. It is an ASP file, so you will need to be on an NT server...

It gives you a count of words seperated by spaces. If there are extra spaces on either end it removes those. But, if there are say two spaces between a word, it will count that as two words, so make sure your users understand to type correctly

You need to change "your_field_name" to what ever is the name of the field the user submits. "WordCount" is the variable that holds the final count. Here goes:

<%
Dim wordCount, arrWords, strOneWord
wordCount = 0
strSentence = Request("your_field_name")
strSentence = Trim(strSentence)
arrWords = Split(strSentence, " ", -1, 1)
For Each strOneWord in arrWords
wordCount = wordCount +1
Next
Response.Write(wordCount) & "<BR>"
%>

Joe

[This message has been edited by jbennett (edited 04-03-2001).]


(in reply to FrogMan)
FrogMan

 

Posts: 108
From: Lewiston, Idaho US
Status: offline

 
RE: Counting Words - 4/3/2001 15:51:00   
Joe,

Thank you very much. This looks like what I originally had in mind. I'll let you know how it works out. It will be later this evening before I get too it, but I'll be checking back.


(in reply to FrogMan)
Mojo

 

Posts: 2441
From: Chicago
Status: offline

 
RE: Counting Words - 4/4/2001 13:25:00   
FrogMan,

I saw a tip today that reminded me of your post. The below code will still give you a count of words seperated by spaces and will remove spaces at the beginning and end.

It will also remove any instance of double spaces. So if someone puts 2 spaces between a word like <--this it will remove one of the spaces. Also works for those people who put two spaces before a new sentence. Like me

code:

<%
Dim wordCount, arrWords, strOneWord
wordCount = 0
strSentence = Request("SearchText")
strSentence = Trim(strSentence)
Do While InStr(1, strSentence, " ")
strSentence = Replace(strSentence, " ", " ")
Loop
arrWords = Split(strSentence, " ", -1, 1)
For Each strOneWord in arrWords
wordCount = wordCount +1
Next
Response.Write(wordCount)
%>

[This message has been edited by jbennett (edited 04-04-2001).]

[This message has been edited by jbennett (edited 04-04-2001).]


(in reply to FrogMan)
FrogMan

 

Posts: 108
From: Lewiston, Idaho US
Status: offline

 
RE: Counting Words - 4/4/2001 13:57:00   
Joe,

Thanks for the update. Actually have not had an opportunity to try the first (death in family), but I will be getting back on it before this weekend. The enhancement for not "counting" double spaces is excellent.

Thanks again


(in reply to FrogMan)
Page:   [1]

All Forums >> Web Development >> General Web Development >> Counting Words
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts