Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Add numbers with JavaScript

Featured Replies

  • Newbies

I look in all the posts and find nothing. So if somebody can help me.

Say I have two fields. One is a name of a project and the other is a total for the project. I can have many records for a project. Something like B)

Field 1 field 2

project1 120,50

project1 50,25

project1 30,25

project2 323,67

project2 63,63

project2 23,67

In a javascript, I want to add the numbers so i can have sub-summary for each project.

In my script in Javascript I have a line like this within a [fmp-record]

TotalProject += "[FMP-Field:TotalBCNet]";

My problem is that it does not add the numbers so the result would be 200,00 for project1 but write Project1 120,5050,2530,25

Does somebody have an answer?

Thanks

Jacques

It looks as if it is reading your numbers as text, Perhaps if you took the Double quotes off around your [FPM-Field:TotalBCNEt]

If I'm not mistaken, in Javascript, you only use double quotes in a calculation if your doing text. That would be my first guess.

  • Author
  • Newbies

I try that too. But then nothing show up in the page. I am french speaking (I hope I don't do much mistakes in writing). In french the way to write the numbers are different. We use the coma to divide the dollars with the cents (1,00 instead of 1.00). In the database, I have a calculation field that change the coma for a point. When I look at the code of the page the numbers are there but nothing appears in the page.

Here is the whole script.

<script LANGUAGE="JavaScript">

var TotalProjet = 0; var TotalParProjet = 0; var Projet = "";

[FMP-Record]

if (Projet == "[FMP-Field:BCProjet]")

{

TotalParProjet +=[FMP-Field:TotalBCNetAff];

TotalProjet +=[FMP-Field:TotalBCNetAff];

}

else

{

document.write(TotalProjet + " " + TotalParProjet + "<br>");

Projet = "[FMP-Field:BCProjet]";

TotalParProjet += [FMP-Field:TotalBCNetAff];

TotalProjet += [FMP-Field:TotalBCNetAff];

} ;

[/FMP-Record]

document.write(Projet + " " + TotalParProjet + "<br>");

document.write("Total : " + TotalProjet);

</script>

It's a script that I copy fron that forum which I appreciate a lot. Thank you for the help.

Jacques

Since i'm not to proficent with Javascript anymore, I would suggest doing it in Filemaker then. Its easy to set up a calculation field the way you want, why not just do that?

Here is a thread that may be of interest:

Summaries

Good Luck.

Garry

  • Author
  • Newbies

Thank you all for your replies. It will help me.

Jacques

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.