Skip to main content
wanderwomanyeg
Participating Frequently
July 9, 2018
Answered

Java Script for Form

  • July 9, 2018
  • 2 replies
  • 1807 views

I am trying to add in proper script for my form in order to calculate certain fields but am running into NaN (Not a number) error codes.

Additionally, I would prefer for all cells to remain blank until filled in and they start to populate. I would also like to format the first three columns in the table as number (currency) and the last one as percentage but am running into additional error codes when doing so.

To my understanding, I need custom calculation script rather than my simplified field notation to ensure I am able to do this but I am not familiar enough with JavaScript to do this myself. I have taken a partial screen shot of the specific table I am talking about below:

 
 
 
I would be looking for the proper JavaScript to put into columns 3 and 4. Any assistance you can provide would be greatly appreciated! Thank you in advance for your time
 
 
 
 
 
 
 
 
 


This topic has been closed for replies.
Correct answer try67

The basic code for such a calculation would be:

var v1 = Number(this.getField("FieldName1").valueAsString);

var v2 = Number(this.getField("FieldName2").valueAsString);

if (v2==0) event.value = "";

else event.value = v1/v2;

2 replies

Legend
July 10, 2018

We can help you if you are willing to learn to be a programmer.

try67
Community Expert
Community Expert
July 9, 2018

Are you trying to do division, by any chance? If so, you have to use a script to make sure the denominator is not empty or zero, as that's an illegal operation.

wanderwomanyeg
Participating Frequently
July 10, 2018

I am!

I am looking for the script in column 4 that I would need to, in essence, divide Amount Paid by Employee by Estimated Costs. For the third column I used simplified notation to find the difference between Estimated Costs and Amount of Support Requested but I still get the 0 showing up when nothing else is entered (and I can't format it to number or the last column to percentage without errors coming up).

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 10, 2018

The basic code for such a calculation would be:

var v1 = Number(this.getField("FieldName1").valueAsString);

var v2 = Number(this.getField("FieldName2").valueAsString);

if (v2==0) event.value = "";

else event.value = v1/v2;