4 Replies Latest reply on Aug 3, 2016 4:43 PM by Monteigo99

# How to script: If (field 1 through 5 ="N/A") event.value="N/A"

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

• ###### 1. Re: How to script: If (field 1 through 5 ="N/A") event.value="N/A"

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.

• ###### 2. Re: How to script: If (field 1 through 5 ="N/A") event.value="N/A"

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".

• ###### 3. Re: How to script: If (field 1 through 5 ="N/A") event.value="N/A"

Apologies.

This was just a copy and paste error.

var
totalY = 0;

var
total = 0;

for

• ###### 4. Re: How to script: If (field 1 through 5 ="N/A") event.value="N/A"

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;