Jump to content

Simple SUM question


Recommended Posts

Hello,

I want to display the sum of all numbers in a column on the results page. The numbers are currency. I prefer for the sum to be showed at the top of the page or above the respective column and denote that it is the sum of that column. Any code as to how to achieve this?

Link to comment
Share on other sites

I do not think the script is faulty, it works for my app. It just needs to be customized according to your results table and column indexes.

For example if you have a download option enabled on your results page you need to reference the results table with index 2 because it will be the third table in the page.

I would suggest if you use Firefox browser and add Firebug add-on which shows you the errors on the page. This way you can better address the issue as it spots the lines you have errors on your code. After all, even if you missed to change or typed wrongly of a single field name, it won't work.

Link to comment
Share on other sites

If you have your columns format to show as currency, the reason the script is Displaying a total of "0" is that each time the code comes to an element in the designated column, it's not accounting for the currency symbol (e.g. - "$", "€") and punctuations (e.g. - "," in the thousands, millions... place) and is returning a value of "0".

Remedy to remove the symbols for NaN ("Not a Number") Clarification:

replace -

"

v_rev = cells[COLUMNNUMBER].innerHTML;

if ( v_rev != " " && !isNaN(v_rev.substr(1)))

"

with -

"

v_rev = cells[COLUMNNUMBER].innerHTML;

v_rev = v_rev.replace(/,/gi, '')

v_rev = v_rev.replace(/$/gi, '')

v_rev = v_rev.replace(/€/gi, '')

if ( v_rev != " " && !isNaN(v_rev))

"

Link to comment
Share on other sites

One last modification:

Replace:

"

v_rev = v_rev.replace(/,/gi, '')

v_rev = v_rev.replace(/$/gi, '')

v_rev = v_rev.replace(/€/gi, '')

"

With:

"

v_rev = v_rev.replace(",", "")

v_rev = v_rev.replace("$", "")

v_rev = v_rev.replace("€", "")

"

Link to comment
Share on other sites

  • 1 month later...
  • 4 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...