Copy link to clipboard
Copied
I'm converting a Projected Operating Costs spreadsheet from Excel to Adobe since some of my end users do not have Excel and Google takes away the security features in the document.
I have no experiencing with Java and am really struggling grasping how to write an if then statement for one of the fields.
The Text field needs to look at another field "S2HRFreeCount" and determine if it is greater than '0'. If it is greater than '0' I want it to display the value I have entered in another field "S2HRFreeRate." This rate changes every year so I'm wanting to use it from the field rather then enter the value in the script. Less places to update. If there is no text in "S2HRFreeCount" than I want the field to either be blank or display "0."
My end user does not need to enter a value in field S2HRFreeCount.
Any assistance would be appreciated. I've only started creating Adobe Fillable Forms within the last 6 months so I'm learning as I go. And this is the most complicated component so far.
The easiest way to do this is a Custom Calculation script on the text field.
var cFreeCount = this.getField("S2HRFreeCount").valueAsString;
if((cFreeCount != "") && !isNaN(cFreeCount) && (Number(cFreeCount) > 0))
event.value = this.getField("S2HRFreeRate").value;
else
event.value = "";
Note that there are 3 conditions used to determine whether or not the FreeRate value is used.
The FreeCount field is not empty, it's value is a number, and that number is greater than 0;
You can r
...Copy link to clipboard
Copied
The easiest way to do this is a Custom Calculation script on the text field.
var cFreeCount = this.getField("S2HRFreeCount").valueAsString;
if((cFreeCount != "") && !isNaN(cFreeCount) && (Number(cFreeCount) > 0))
event.value = this.getField("S2HRFreeRate").value;
else
event.value = "";
Note that there are 3 conditions used to determine whether or not the FreeRate value is used.
The FreeCount field is not empty, it's value is a number, and that number is greater than 0;
You can read more about calculation scripts here:
https://www.pdfscripting.com/public/Calculating-field-values-and-more.cfm
And about if statements in calculations here:
https://acrobatusers.com/tutorials/conditional-execution/
Copy link to clipboard
Copied
Thank you. I have so much more to learn about these advance features in Adobe. But making the conversion to Adobe will make my life so much easier in the long run.
Copy link to clipboard
Copied
I am stuggling to get this working.
( BldgPermitFee+ElectFee+PlumbingFee+SignFee+COO )= < 10,000 than *.2
( BldgPermitFee+ElectFee+PlumbingFee+SignFee+COO )= between 10,001 - 20,000 than *.12
( BldgPermitFee+ElectFee+PlumbingFee+SignFee+COO )= between 20,001 - 30,000 than *.10
( BldgPermitFee+ElectFee+PlumbingFee+SignFee+COO )= between 30,001 - 40,000 than *.09
( BldgPermitFee+ElectFee+PlumbingFee+SignFee+COO )= > 40,000 than *.08
Copy link to clipboard
Copied
Is this a custom calculation script? I'll just assume it is for the answer.
First, you have to actually have an if/then structure and use Acrobat JavaScript functions.
I'd suggest reading these articles:
https://www.pdfscripting.com/public/PDF-Form-Scripting.cfm
https://acrobatusers.com/tutorials/conditional-execution/
Here's how you set it up. The important bit for a calculation is that the calculated value is assigned to "event.value".
var nSum = this.getField("BldgPermitFee").value + this.getField("ElectFee").value + this.getField("PlumbingFee").value + this.getField("SignFee").value + this.getField("COO").value;
if(nSum <= 10000)
event.value = 0.2;
else if (nSum <= 20000)
event.value = 0.12;
...etc...
Copy link to clipboard
Copied
Thank you I did find one mistake I keep doing but its still not working and i have read the artcles and made changes. It there something else I could be missing?
Copy link to clipboard
Copied
Well, the question is - "What's not working". This is the first part of figuring out whats wrong. What values appear in the text box when you enter data? Are any errors reoported in the Console Window? Did you fill out the rest of the "if" block? I only provided the first two cases as a sample of how it should be done. Are all the field names correct?
Post the exact script you are using. We can't tell you anything without information.
Copy link to clipboard
Copied
var nSum = this.getField("BldgPermitFee").value + this.getField("ElectFee").value + this.getField("PlumbingFee").value + this.getField("SignFee").value + this.getField("COO").value;
if(nSum <= 10000) event.value * 0.2; else if (nSum <= 20000) event.value * 0.12; else if (nSum <= 30000) event.value *.10; else if (nSum <= 40000) event.value *.09; else if (nSum > 40000) event.value * .08
The values are not appearing in the box. it just says 0.
Everything for the fields is correct compared to my form.
Thank you so much I have been reading articles and could not get it.
Copy link to clipboard
Copied
The result of any calculation must be placed in "event.value".
That is why the code I provided uses the "=" symbol, For example: event.value = 0.2;
The result you want is not clear from your post. Did you want the field value to be the "sum" times the decimal value? If so, then use code like this: event.value = nSum * 0.2;
Copy link to clipboard
Copied
Copy link to clipboard
Copied
There's an unsubscribe link at the bottom of each email you're getting from this forum.