Skip to main content
Participant
Oct 24, 2020 10:37 PM UTC
Answered

Simple Fillable Form Calculation- Division

Hi,

I need my fillable form to automatically divide two sub-totals.  What is the javascript code that I need to place in the last line to get these two subtotals (Cash Availability/CashNeedsFor30Days) to divide?  Thank you in advance!  

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Oct 25, 2020 9:13 AM UTC

Use this code as the custom calculation script:

 

var v1 = Number(this.getField("Cash Availability").valueAsString);
var v2 = Number(this.getField("Cash Needs for 30 Days").valueAsString);
if (v2==0) event.value = "";
else event.value = v1/v2;

7 replies

Nesa Nurani
Community Expert
Community Expert
Oct 25, 2020 7:03 AM UTC

Write this in "Simplified Field Notation":  Cash\ Availability/CashNeedsFor30Days

Translate
Participant
Oct 25, 2020 2:46 PM UTC

Unfortunately, this one wouldn't work for me.  I don't understand why, but it wouldn't divide the fields.  The above custom calculation script did the trick though.  Thank you for reaching out - greatly appreciated!!

Translate
Nesa Nurani
Community Expert
Community Expert
Oct 25, 2020 3:07 PM UTC

Thats because I thought  your field name is "CashNeedsFor30Days" but it's "Cash Needs for 30 Days"

the code should be: Cash\ Availability/Cash\ Needs\ for\ 30\ Days

It's better not to use spaces in field names if using SFN.

Translate
try67
Community Expert
Community Expert
Oct 24, 2020 10:53 PM UTC

Divide by what? 2? What's the name of the field that contains the sub-total you want to divide?

Translate
Participant
Oct 24, 2020 11:20 PM UTC

Field Name "Cash Availability" divided by "Cash Needs for 30 Days".

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Oct 25, 2020 9:13 AM UTC

Use this code as the custom calculation script:

 

var v1 = Number(this.getField("Cash Availability").valueAsString);
var v2 = Number(this.getField("Cash Needs for 30 Days").valueAsString);
if (v2==0) event.value = "";
else event.value = v1/v2;

Translate