Highlighted

Assign a value to "NA" in PDF dropdown?

Community Beginner ,
Jul 28, 2020

Copy link to clipboard

Copied

Using Acrobat DC.

I have five dropdown boxes (Rank1.1, Rank1.2, Rank1.3, Rank1.4, Rank1.5), each has options 1,2,3,4,5,NA. A sixth box (RankAvg1) simply calculates the average of the five boxes and runs a validation script to show no value until a number is entered into one of the dropdowns: 

if(event.value == 0)event.value = "";

I wish to have the choice of "NA" be considered a value of 3 in RankAvg1. Is that possible?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You can use this code as the custom calculation script of your Average field to do it:

 

var total = 0;
for (var i=1; i<=5; i++) {
	var f = this.getField("Rank1."+i);
	if (f.valueAsString=="NA") {
		total+=3;
	} else total+=Number(f.valueAsString);
}
event.value = total/5;

 

However, the result can't be zero, since you didn't add a default blank value to the drop-downs.

Views

110

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Assign a value to "NA" in PDF dropdown?

Community Beginner ,
Jul 28, 2020

Copy link to clipboard

Copied

Using Acrobat DC.

I have five dropdown boxes (Rank1.1, Rank1.2, Rank1.3, Rank1.4, Rank1.5), each has options 1,2,3,4,5,NA. A sixth box (RankAvg1) simply calculates the average of the five boxes and runs a validation script to show no value until a number is entered into one of the dropdowns: 

if(event.value == 0)event.value = "";

I wish to have the choice of "NA" be considered a value of 3 in RankAvg1. Is that possible?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You can use this code as the custom calculation script of your Average field to do it:

 

var total = 0;
for (var i=1; i<=5; i++) {
	var f = this.getField("Rank1."+i);
	if (f.valueAsString=="NA") {
		total+=3;
	} else total+=Number(f.valueAsString);
}
event.value = total/5;

 

However, the result can't be zero, since you didn't add a default blank value to the drop-downs.

Views

111

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Jul 28, 2020

Copy link to clipboard

Copied

I moved your post over from the poorly named Community Help forum, which is for getting help using this forum system, to a better forum.


I hope this helps. Best of luck to you.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 28, 2020

Copy link to clipboard

Copied

What calculation does you use?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Most Valuable Participant ,
Jul 29, 2020

Copy link to clipboard

Copied

You can use this code as the custom calculation script of your Average field to do it:

 

var total = 0;
for (var i=1; i<=5; i++) {
	var f = this.getField("Rank1."+i);
	if (f.valueAsString=="NA") {
		total+=3;
	} else total+=Number(f.valueAsString);
}
event.value = total/5;

 

However, the result can't be zero, since you didn't add a default blank value to the drop-downs.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jul 29, 2020

Copy link to clipboard

Copied

Hi,

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Most Valuable Participant ,
Jul 30, 2020

Copy link to clipboard

Copied

The result of "NaN" (Not a Number) means it's trying to add up a value that isn't a number. Are you sure your values are exactly what you said they were? Can you share the actual file with us?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jul 30, 2020

Copy link to clipboard

Copied

How do I upload a file here?

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Most Valuable Participant ,
Jul 30, 2020

Copy link to clipboard

Copied

You can attach it to the original message using the tiny paperclip icon at the bottom when you edit it, or upload it to a file-sharing website (like Dropbox, Google Drive, Adobe Cloud, etc.), generate a share link and then post it here.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jul 30, 2020

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Most Valuable Participant ,
Jul 30, 2020

Copy link to clipboard

Copied

As I suspected, the values of your drop-downs are not what you said. For example, in "Rank1.1" the value is not "NA", but " NA" (with several spaces at the start). Also, the values are not consistent in all of the drop-downs and it's quite confusing. I recommend you go over them and make sure they all have the same values, without any spaces, and then it should work.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jul 30, 2020

Copy link to clipboard

Copied

I'm sorry. I didn't realize these things are this critical. I added the three spaces before NA so that it shows up centered in the box. Can I add the three spaces in the code or some other way center the letters in the field? 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Most Valuable Participant ,
Jul 30, 2020

Copy link to clipboard

Copied

Yes, it's critical. The strings have to match exactly. If you add them in the code then it won't recognize those values that don't have three spaces before "NA".

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 30, 2020

Copy link to clipboard

Copied

In your code you can remove the spaces before you test the value.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jul 30, 2020

Copy link to clipboard

Copied

Got it. I took out the spaces and it worked in Rank1. Yay!

Now, for the four other remaining sets I pasted the same code into all five Averages fields: (RankAvg1 - RankAvg5). I changed from Rank1. to Rank2. and Rank3. Rank4 and Rank5. but only tally for RankAvg1 is affecting the TotalAvgs field.  See the pictures I sent yesterday. Thanks.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Most Valuable Participant ,
Jul 30, 2020

Copy link to clipboard

Copied

See Bernd's reply below.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jul 29, 2020

Copy link to clipboard

Copied

Thank you Try67. More to the story.

I failed to mention some things that I thought were insignificant but now see that maybe they were not. Sorry.

Although I only described a single set of five drop-downs with an Average field, the document actually has five such sets.

There is also a Total Averages field that sums up the five Averages then runs a validation script that auto-populates one of several corresponding Check Boxes:

(provided previously by Try67. Thank you very much!)

var total = 0;

for (var i=1; i<=5; i++) {

                    var f = this.getField("Rank1."+i);

                    if (f.valueAsString=="NA") {

                             total+=3;

                    } else total+=Number(f.valueAsString);

}

event.value = total/5;

 

Now, after adding the new calculation script to each of the five Averages fields (Changed the section Rank1. to Rank2., Rank3., Rank4. and Rank5 accordingly. See below)  

          var f = this.getField("Rank1."+i);

Several things happened when I ran the new calculation script:

1, If a number is selected from the Rank1 drop-downs all functions (including TotalAvgs field) work properly.

  1. If “NA” is selected from the Rank1 drop-downs it returns “NaN” in RankAvg1 and repeats it: “NaN” in the TotalAvgs field.
  2. If a number is selected from any Rank2 – Rank5 drop-downs their Averages field tallies correctly but the TotalAvgs field is not changed.
  3. If "NA" is selected from any Rank2 - Rank5 drop-downs their Averages field returns "NaN" but it is not repeated in the TotalAvgs field. 

 

For the picture I moved the TotalAvgs field up so you could see it. 

Any help would be appreciated

 

Error - Seen in RankAvg1 and TotalAvgsError - Seen in RankAvg1 and TotalAvgs

 

Error - Seen in RankAvg2 but not in TotalAvgs fieldError - Seen in RankAvg2 but not in TotalAvgs field

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 30, 2020

Copy link to clipboard

Copied

Check the field calculation order.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jul 30, 2020

Copy link to clipboard

Copied

It wasn't the calculation order. I had entered things incorrectly elsewhere. Thank you for your help.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Chosen4? LATEST
Community Beginner ,
Jul 30, 2020

Copy link to clipboard

Copied

The code provided by try67 was precisely what I needed. All of the other problems beyond that point were simply operator errors. Thank you try67 and all else who jumped in. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Participant ,
Jul 30, 2020

Copy link to clipboard

Copied

From what I can see you didn't give any item export value.

Give item 1 export value 1, item 2 export value of 2...etc for NA give it export value of 3(or any other number you want).

then in "Average" field just use "value is the" in calculate tab and then "pick" your fields.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Resources
One Stop Solution for Acrobat
Edit a PDF