Copy link to clipboard
Copied
I'm
still learning and have a script as follows:
var
totalY = 0;
var
total = 0;
for
var totalY = 0;
var total = 0;
for (var i=1; i<=5; i++) {
var f = this.getField("JDCRDropdown"+i);
if (f.valueAsString=="Y") {
totalY++;
total++;
} else if (f.valueAsString=="N") {
total++;
}
}
if (total==0) event.value = "N/A";
else event.value = totalY + " of " + total;
The
problem is that and N/A is different than zero of zero. If I leave as is, then the output field defaults to N/A. If I remove: if (total==0) event.value = "N/A"; then it spits out 0 of 0 as the default. What I need is for it to default to 0 of 0, UNLESS all 5 fields are N/A. Then I need the output to be N/A.
ALL 5 fields must have N/A selected in order for it to populate N/A.
I've attempted a few different scripts to no avail.
Thanks
Add a variable to keep track of the number of "N/A" selections, and if it's 5 after the loop, set the field value to "N/A".
Copy link to clipboard
Copied
Why are defining the variables total and totaly twice. Once outside your loop and then again the loop. This is causing a scope issue. Define these variables once. You msy also have a rounding issue caused by Acobat's use of IEEE 16 bit floating point conversion.
Copy link to clipboard
Copied
Apologies.
This was just a copy and paste error.
var
totalY = 0;
var
total = 0;
for
Copy link to clipboard
Copied
Add a variable to keep track of the number of "N/A" selections, and if it's 5 after the loop, set the field value to "N/A".
Copy link to clipboard
Copied
This is fun. This is what I came up with. Thanks
var totalY = 0;
var total = 0;
var totalNA = 0;
for (var i=1; i<=5; i++) {
var f =
this.getField("JJCRDropdown"+i);
if
(f.valueAsString=="Y") {
totalY++;
total++;
} else if
(f.valueAsString=="N") {
total++;
} else if (f.valueAsString=="N/A")
{
totalNA++;
}
}
if (totalNA==5) event.value = "N/A";
else event.value = totalY + " of " + total;
Find more inspiration, events, and resources on the new Adobe Community
Explore Now