Copy link to clipboard
Copied
I'm using Acrobat Pro DC. My form has a column of 12 randomly named fields (product names) with dollar values. Each field is made visible or hidden with it's own checkbox action. I want to sum the column, but only the fields that are visible that have the boxes checked. I need a script that will determine which fields are visible, then sum them in a separate "Total" field. I don't know Javascript, but can do basic script editing make them work for me, like adding field names.
I am guessing this is pretty basic, but thanks for your any help you can provide!
It would be easiest if you use a custom calculation script for the Total field. The following is incomplete, but should get you started:
// Custom calculation script for Total field
// Initialize variable
var sum = 0;
// Add first field value if its corresponding check box is selected
if (getField("item1_checkbox").value !== "Off") {
sum += +getField("product1").value;
}
// Add second field value if its corresponding check box is selected
if (getField("item2_checkbox").value !== "Off") {
sum += +g
...Copy link to clipboard
Copied
If you set the value to sum for the item to 0, zero, for the unselected state and the value when selected you can sum the values.
Copy link to clipboard
Copied
Sorry, but I have no idea what you just said
. I don't know anything about scripting. I'm going to need a script i can copy & paste into the javascript field in Acrobat
Copy link to clipboard
Copied
It would be easiest if you use a custom calculation script for the Total field. The following is incomplete, but should get you started:
// Custom calculation script for Total field
// Initialize variable
var sum = 0;
// Add first field value if its corresponding check box is selected
if (getField("item1_checkbox").value !== "Off") {
sum += +getField("product1").value;
}
// Add second field value if its corresponding check box is selected
if (getField("item2_checkbox").value !== "Off") {
sum += +getField("product2").value;
}
// Repeat for other 10 values
// Set this field value to the sum, or set to blank if zero
if (sum > 0) {
event.value = sum;
} else {
event.value = "";
}
You will have to replace the field names used with the getField calls with the actual field names you're using. Be sure to use the exact field names (case matters) and check for errors by displaying the JavaScript console (Ctrl + J). This script could be made more compact and efficient, but it should get you started.
Copy link to clipboard
Copied
Thanks George.
Something isn't working. I replaced in the checkbox field names in "item#_checkbox", and product value fields in the "product#" (for all fields 1-12).
It sums all the values in the the column whether the checkbox is checked or not.
It may be worth mentioning the values are static in the "product#" fields; they are a fixed number.
Can I somehow send you a sample of the form so you can see exactly what I'm doing?
Thanks. I'm heading out for Thanksgiving so may not get back until Monday. Happy Thanksgiving!
Copy link to clipboard
Copied
George,
I retried your script and it works perfectly. My error was I didn't clear the sum field so it had an existing value. I guess I was thinking more about turkey and stuffing than work.
Thank you for help!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more