Copy link to clipboard
Copied
I have 10 Dropdown boxes all named "satunsat.#" (# is 0-9). I want to count the number of "SAT" and "UNSAT" answers and provide a percentage. The percentage is no big deal I already do that in a couple of other fields. But how do I get it to count those answers? Also I use "-" for my blank value and not all 10 dropdowns will be used. It varies depending on information available. So sometimes I will have 6 total answers, or 5, or 10 or even just 2.
-
SAT
UNSAT
Copy link to clipboard
Copied
Here's a script that will provide the total number of answers and number that are SAT
// Initialze summing variables
var nTotal = 0, nSAT = 0;
// This line gets an array of all the fields in the "satunsat" group
var aFldList = this.getField("satunsat").getArray();
// Loop over fields and count values, note that total is counted for both cases.
for(var i=0;i<aFldList.length;i++)
{
switch(aFldList[i].value)
{
case "SAT":
nTotal++;
nSAT++;
break;
case "UNSAT":
nTotal++;
break;
}
}
Copy link to clipboard
Copied
Ok. I am still learning and I am used to just calculating fields and I haven't worked with switch statements. This is a document level script where I have to use:
function switchResult
to pull the value from each case?
I'm trying to actually learn. And help is appreciated. Like I said I have never used this before.
Copy link to clipboard
Copied
This is just basic code. It is not intended to be used in any particular way. It shows how to count the numbe of selections in a group of dropdowns with the list items.
Since you are learning about scripting in Acrobat I would strongly suggest you test this code in the console window to both ensure it is doing what you want, but also to be come more familiar with scripting, and the Acrobat scripting envrionment.
Watch the console window tutorial here. In fact, watch several of the videos. Even the ones recorded on older versions of Acrobat are up to date for the scripting.
https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro
After this, think about how you want this to work and post it, and we'll help you integrate this code in the form.