Copy link to clipboard
Copied
I am trying to make a form that arranges $ values when two fields match. The form has multiple rows (12 rows max) that calculate a $ value. Then at the end of each row, I have a drop-down (dropdown1) where you can select a fund source; FJC-HT, ARA-JC, and CB Cap are some examples.
At the bottom of the form, I want a cumulative total of the $ values for each selected fund source. I have another drop-down (dropdown2)with the same options as drowpdown1. I want to combine the 4 values of each row when these two drop-downs match. So if 3 rows have FJC-HT selected, I want the combined $ value of each row with FJC-HT in one field box next to dropdown2. Then if other sources are selected, they will be combined at the bottom respectively.
Copy link to clipboard
Copied
You can use something like this code as the custom Calculation script of the first total field you've described:
var total = 0;
for (var i=1; i<=12; i++) {
if (this.getField("dropdown"+i).valueAsString=="FJC-HT") {
total+=Number(this.getField("amount"+i).valueAsString);
}
}
event.value = total;
Adjust the field names and text strings as needed.
Copy link to clipboard
Copied
I appreciate your support. I tried your suggested coding, but it doesn't produce the desired effect after applying my field names. I attached an image of the form I am working with to help better describe what I am hoping to achieve.
When an option is selected in "f1" - "f12", I want those options to be populated in fields "f1a" - "f12a", but I want the selections in "f1" - "f12" that are the same to combine in "f1a" - "f12a". Then I want the $ values in field "a1" - "a12" to follow the selected "f1" - "f12" options to the field next to matching "f1a" - "f12a"
So if, for example, "FJC-HT" is selected as an option, let's say "f1" "f2" and "f3". and its "a" values are $12, $3.75, and $5, respectively. I want "f1a" at the bottom to populate with "FJC-HT," and I want "s1" to show the combined $ value of the "a"s. Then if other options are selected, I want them to match, and populated to "f2a" and on as needed.
Copy link to clipboard
Copied
What happens when you use it, exactly? Are there any error messages in the JS Console?
Can you share the actual file with us?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Press Ctrl+J to open the JS Console and you'll see an error message appear after you edit the value of any field. I also don't see where you applied the code I provided...
Copy link to clipboard
Copied
I made some minor adjustments to the code and it works fine:
var total = 0;
for (var i=1; i<=12; i++) {
if (this.getField("f"+i).valueAsString=="FJC - HT") {
total+=Number(this.getField("a"+i).valueAsString);
}
}
event.value = total;
Copy link to clipboard
Copied
I see what I was doing wrong with the names I was using to replace with your original placeholders. Thank you!
Copy link to clipboard
Copied
Note I also adjusted the value it looks for, from "FJC-HT" (as you originally wrote) to "FJC - HT" (as it actually appears in the file). Even a single space out of place would cause it to not work properly.
Copy link to clipboard
Copied
The copy I provided was a code-free version. But I was testing your provided code on the first "sub" box of the bottom part of the form. If you are looking the Field names, its the one labeled "s1"
Copy link to clipboard
Copied
Yes, that's where I put the code above and it worked fine.
Copy link to clipboard
Copied
Can "FJC -HT" be replaced with some kind of code that represents any of the available options in the drop-down? That way I don't have to have a box with this code for every possible option.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more