473,405 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to calculate number of words with given price?

Hi,

I am Web Designer.

I am new to this coding related job. Can anyone help me how to sort this out.

How to calculate number of words with given price?

Thanks.
Sarfraz
Attached Images
File Type: jpg calculate.jpg (12.5 KB, 185 views)
Aug 31 '10 #1

✓ answered by gits

it is a bit unreliable to calculate the price clientside since that could easyly be modified by the user - so to have a solid calculation you would need a serverside calculation too. to give the user a price-preview you might do it with javascript ... a simple approach would be to retrieve the text from the textarea and then the number of the words is roughly:

Expand|Select|Wrap|Line Numbers
  1. var textareaNode = document.getElementById('textareaId');
  2. var noOfWords = textareaNode.value.split(' ').length;
this would give you the 'wordcount' depending on whitespace-separated 'character-groups' ... in case you would need more specific rules to count the words like 'she's' should be two words? then you would need a bit more preparing processing of the text.

6 2092
gits
5,390 Expert Mod 4TB
it is a bit unreliable to calculate the price clientside since that could easyly be modified by the user - so to have a solid calculation you would need a serverside calculation too. to give the user a price-preview you might do it with javascript ... a simple approach would be to retrieve the text from the textarea and then the number of the words is roughly:

Expand|Select|Wrap|Line Numbers
  1. var textareaNode = document.getElementById('textareaId');
  2. var noOfWords = textareaNode.value.split(' ').length;
this would give you the 'wordcount' depending on whitespace-separated 'character-groups' ... in case you would need more specific rules to count the words like 'she's' should be two words? then you would need a bit more preparing processing of the text.
Aug 31 '10 #2
Thanks for the info will work on the concept. Thanks very much
Sep 1 '10 #3
kovik
1,044 Expert 1GB
That solution is too basic. What about surrounding whitespace and double-spaces? Sometimes that double-space might even start looking like a triple-space! :p


You should trim the whitespace off of the edges and condense the internal whitespace, THEN split the string. I'd make it into a function. Hell, I'd add it to the String object. In fact, I shall. :3


Functions:
Expand|Select|Wrap|Line Numbers
  1. String.prototype.trim = function() {
  2.   return this.replace(/^\s+/,'').replace(/\s+$/,'');
  3. }
  4.  
  5. String.prototype.condense = function() {
  6.   return this.replace(/\s+/,' ');
  7. }
  8.  
  9. String.prototype.words = function() {
  10.   return (this.trim().condense().split(' ')).length;
  11. }

Test:
Expand|Select|Wrap|Line Numbers
  1. alert(("  this is   a test    string    ").words());

Result:
Expand|Select|Wrap|Line Numbers
  1. 5
:)
Sep 2 '10 #4
gits
5,390 Expert Mod 4TB
of course - i just wanted to show a start - it could even be extended to find out divided words etc.
Sep 2 '10 #5
kovik
1,044 Expert 1GB
No doubt. :)
Sep 2 '10 #6
Nope thanks bro
Sep 4 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Terry | last post by:
From the packet data returned from a query, where in the packet data are the bytes signifying the number of rows returned? Thanks, Terry
3
by: Frederik Sørensen | last post by:
I'm trying to do this calculation in xsl but i get an error message: "expression is not a node set" <xsl:variable name="height" select="round(130/width*height)+10"/> How do i save the result...
2
by: Rimdur | last post by:
I am trying to get a difference between two dates calculated in a query. I have Sales_Date as the first one, and Date() as the second one. How would I put the difference of these two days into a...
6
by: carl.barrett | last post by:
Hi, I have a continuous form based on a query ( I will also be creating a report based on the same query). There are 2 fields: Date Obtained and Date Of Expiry I want a further 3 columns...
3
by: George | last post by:
Can someone tell me how to calculate the number of weeks between two dates. Your help is appreciated. Thanks, George
7
by: P. Schmidt-Volkmar | last post by:
Hi there, I have a string in which I want to calculate how often the character ';' occurs. If the character does not occur 42 times, the ";" should be added so the 42 are reached. My...
5
by: Beemer Biker | last post by:
I cant seem to get that date into any DateTime to make my calculation directly by subtracting "01-01-0000" from "now". After reading this:...
1
by: oyis | last post by:
Hi, I'm looking for a function,which finds week number of given date. I found this method before,but I can't find now... Please help me...
4
by: shilpareddy2787 | last post by:
Hello, I have some total values, I want to calculate percenatge of these Total Values. I want to divide the total with No. Of working Days Excluding Saturdays and Sundays in a given period. ...
1
by: AXRabbit | last post by:
Hi guys, I am currently doing a Car rental website project. Like my Car collection and return date is like in the website. http://www.avis.com/car-rental/avisHome/home.ac Well i need a function or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.