Copy link to clipboard
Copied
I'm using the following simplified notation to calculate a field:
100-[(Text3/Text1)*100]
If the input for Text3 and Text1 = 0, the result = NaN
I need a script that will return a blank field if the input is zero instead of NaN.
Thanks in advance for your help.
Copy link to clipboard
Copied
Use this:
var v1 = Number(this.getField("Text3").valueAsString);
var v2 = Number(this.getField("Text1").valueAsString);
if (v2==0) event.value = "";
else event.value = 100-((v1/v2)*100);
Copy link to clipboard
Copied
Thank you that worked. Can you help with another question? I am calcuating the total number of filled in fields but do not want to include blank fields in the total. I am calculating the total using the following script:
var total = "";
for (var i=1; i<=7; i++) {
if (this.getField("Total"+i).value != "") total++; }
event.value = total;
How can I keep the blank fields from being included in the total? Thanks again for your help.
Copy link to clipboard
Copied
This code should do that, although you could change value to valueAsString in the third line.
Also, change the initial value of total to 0, instead of ""...
Copy link to clipboard
Copied
Perfect! Thank you.