Copy link to clipboard
Copied
Hi. I'm brand new to editing forms directly in Adobe, and have even less java experience. I've inherited a form someone else set up, and am trying to fix a bad calculation. Well, actually, to add a calucation.
The form is used to request refunds of prepaid admittance fees to an event. It allows you to add up to ten people, depending upon how many you originally registered. Refunds are supposed to cost a $10 per person processing fee. The form creator added ten fields named "Amount1" to "Amount10". They did a calculation for "AmountTotal" using the formula of "Value is the sum (+) of the following fields" and then listed the 10 AmountX fieldnames separated by commas. They then added a field named "AmountLess Processing Fee", but did not add a formula. It currently is hard coded to -$10. Then they created a field named "AmountRefund Due", with a formula of "Value is the sum (+) of the following fields: AmountTotal, AmountLess Processing Fee". If there is more than one person on the form, this does not return the correct value.
I would like to add a calculation to the "AmountLess Processing Fee" field similar to a =counta(Amount1:Amount10)*(-$10) that I'd use in Excel, but I have no idea how to even begin.
Any guidance would be greatly appreciated!
Copy link to clipboard
Copied
Hello,
Absolutely! Let's break down how to fix this calculation in your Adobe form using JavaScript. You're right, simply hardcoding "-$10" won't work when you have multiple people. We need to dynamically calculate the processing fee based on how many "Amount" fields have values.
Here's how you can approach this:
1. Determine Which "Amount" Fields Have Values
We need to iterate through "Amount1" to "Amount10" and count how many of them are not empty.
2. Calculate the Processing Fee
Multiply the count from step 1 by -$10.
3. Update "AmountLess Processing Fee"
Set the calculated processing fee to the "AmountLess Processing Fee" field.
JavaScript Code
Here's the JavaScript code you can use in the "AmountLess Processing Fee" field's Calculate event:
JavaScript
// Get the number of Amount fields with values
var count = 0;
for (var i = 1; i <= 10; i++) {
var fieldName = "Amount" + i;
var field = this.getField(fieldName);
if (field && field.valueAsString !== "") {
count++;
}
}
// Calculate the processing fee
var processingFee = count * (-10);
// Set the value of AmountLess Processing Fee
event.value = processingFee;
How to Implement the Code
Open the Form in Adobe Acrobat Pro: Make sure you're using Adobe Acrobat Pro, not just Adobe Reader.
Open Form Editing Mode: Go to "Tools" > "Prepare Form."
Select the "AmountLess Processing Fee" Field: Click on the "AmountLess Processing Fee" field to select it.
Open the Field Properties: Right-click on the field and select "Properties."
Go to the "Calculate" Tab: In the Field Properties dialog, click on the "Calculate" tab.
Select "Custom Calculation Script": Choose "Custom Calculation Script" from the "Calculation" dropdown.
Click "Edit...": Click the "Edit..." button next to the "Custom Calculation Script" option.
Paste the JavaScript Code: Paste the JavaScript code provided above into the JavaScript Editor window.
Click "OK" and "Close": Click "OK" to close the JavaScript Editor, and then click "Close" to close the Field Properties dialog.
Test the Form: Enter values into the "Amount" fields and see if "AmountLess Processing Fee" updates correctly.
Best Regards
[Spam link removed]
Copy link to clipboard
Copied
Hello,
Absolutely! Let's break down how to fix this calculation in your Adobe form using JavaScript. You're right, simply hardcoding "-$10" won't work when you have multiple people. We need to dynamically calculate the processing fee based on how many "Amount" fields have values.
Here's how you can approach this:
1. Determine Which "Amount" Fields Have Values
We need to iterate through "Amount1" to "Amount10" and count how many of them are not empty.
2. Calculate the Processing Fee
Multiply the count from step 1 by -$10.
3. Update "AmountLess Processing Fee"
Set the calculated processing fee to the "AmountLess Processing Fee" field.
JavaScript Code
Here's the JavaScript code you can use in the "AmountLess Processing Fee" field's Calculate event:
JavaScript
// Get the number of Amount fields with values
var count = 0;
for (var i = 1; i <= 10; i++) {
var fieldName = "Amount" + i;
var field = this.getField(fieldName);
if (field && field.valueAsString !== "") {
count++;
}
}
// Calculate the processing fee
var processingFee = count * (-10);
// Set the value of AmountLess Processing Fee
event.value = processingFee;
How to Implement the Code
Open the Form in Adobe Acrobat Pro: Make sure you're using Adobe Acrobat Pro, not just Adobe Reader.
Open Form Editing Mode: Go to "Tools" > "Prepare Form."
Select the "AmountLess Processing Fee" Field: Click on the "AmountLess Processing Fee" field to select it.
Open the Field Properties: Right-click on the field and select "Properties."
Go to the "Calculate" Tab: In the Field Properties dialog, click on the "Calculate" tab.
Select "Custom Calculation Script": Choose "Custom Calculation Script" from the "Calculation" dropdown.
Click "Edit...": Click the "Edit..." button next to the "Custom Calculation Script" option.
Paste the JavaScript Code: Paste the JavaScript code provided above into the JavaScript Editor window.
Click "OK" and "Close": Click "OK" to close the JavaScript Editor, and then click "Close" to close the Field Properties dialog.
Test the Form: Enter values into the "Amount" fields and see if "AmountLess Processing Fee" updates correctly.
Best Regards
[Spam link removed]
Copy link to clipboard
Copied
Thank you for this very thorough explanation. That helped a lot! This will save me a lot of extra work next time we hold this event. I appreciate the assistance!
Copy link to clipboard
Copied
Use this as custom calculation script of "AmountLess Processing Fee" field:
var count = 0;
for (var i = 1; i <= 10; i++) {
if (this.getField("Amount" + i).valueAsString) count++;}
event.value = count ? count * -10 : 0;

