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.
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.
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).
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;
Thank you so, so much- I really appreciate it! It worked wonderfully and the form looks great!
I am running into some issues with my chart that I was hoping you could help me with.
A percentage field can't be empty. If you want it to be you have to use a different Format settings, such as None, and apply the percentage value manually.
To "lock" the fields simply set them as read-only, under their Properties, General tab.
Perfect- the read only worked great.
I am still having issues with the chart though- specifically when entering in a 0 for column 2- for some reason it does not properly calculate the last 2 columns thus impacting the last row's calculations as well.
What exactly do you expect to show up there?
It might be easier if you could share the file with us (via Dropbox, Google Drive, etc.)...
Ultimately I am looking to calculate:
v1-v2=v3 and v3/v1=v4
However, the difficulty I am having is that I would also like the chart:
- to remain empty when no numbers are input (to avoid NaN errors)
- allow for 0 to be entered for v1 and/or v2 (which currently isn't happening)- when I enter 0 it does not accurately calculate v3 or v4
It should work just fine. You just need to make sure that the calculation order is correct.
Under the Simple Field Notation option in the Calculate tab of v3 enter:
v1 - v2
And for v4 use the code I provided, adjusting the field names, of course.
Will do. Thanks!
We can help you if you are willing to learn to be a programmer.