Copy link to clipboard
Copied
I need to do a division as calculation and I don't know how to do it. I don't know where to find the answer. If nobody answer my question I will probably use another software than Adobe DC. i cannot find my answer on Adobe site. Really bad done
Copy link to clipboard
Copied
Assuming you're working with a form, you'll have to use JavaScript. Here's a sample custom calculate script for a text field:
// Custom calculate script
// Get the field values, as numbers
var numerator = +getField("text1").value;
var denominator = +getField("text2").value;
// Calculate and set this field value
if (denominator !== 0) {
event.value = numerator / denominator;
} else {
event.value = "";
}
You'd have to replace "text1" and "text2" with the actual field names, and perhaps modify this script if you're doing something other than dividing one field value by another.
Also, that last if/else block can be reduced to just the following"
// Calculate and set this field value
event.value = denominator !== 0 ? numerator / denominator : "";
Copy link to clipboard
Copied
Hi - thank you for the above; can you tell me how I can get it to check if another drop-down field = Yes, then run the division calculation. Otherwise, leave value (%) at 0.
Copy link to clipboard
Copied
Change:
if (denominator !== 0) {
To:
if (denominator !== 0 && this.getField("Dropdown1").valueAsString=="Yes") {
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Yes, but you have to replace "Field Name" and "Dropdown1" with the actual names of the fields in your file...
Copy link to clipboard
Copied
Copy link to clipboard
Copied
When I write the code you gave me it does not work. When I write 'this.getField' instead of +getField it works. Why?
Copy link to clipboard
Copied
The "this" keyword can sometimes be dropped when it is applied from the context, but I don't like this habit and recommend to always use it. Others disagree.
Copy link to clipboard
Copied
Where exactly did you place the code?