Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Total Answers From Multiple Drop-down Lists

Avatar

Former Community Member

Hello:

I have a form that is a series of 14 questions.  Each question has a drop-down list with 4 possible answers (yes, no, N/A, not observed).

I need to show a total of the answers (number of yes, number of no, etc) at the end of the form.

Not real experienced at using scripts, but willing to learn...

Thanks!

1 Accepted Solution

Avatar

Correct answer by
Level 8

You may need to expand the scope of the conditional expression to include the table.

Something like:

this.rawValue=xfa.resolveNodes('Table.Row.[Cell1.rawValue=="1"]').length;

That's without seeing your exact hierarchy.

Kyle

View solution in original post

9 Replies

Avatar

Level 10

I've uploaded a sample here: https://workspaces.acrobat.com/?d=7W8lXkoUZuLp4r1xpyagUw

The sample assumes a couple of things:

  • all the dropdowns are in the same subform and have the same name (so they get an instance number in the hierarchy - the number in square brackets after the name).
  • the dropdowns have values assigned for the responses - I've done 1-4 for yes, no, n/a, not observed (you could do this with the names but I find the values easier).

The script is on the click event of the "click me" button and puts the values into the four fields below.

This is the script that's on the button:

// get the list of ddls

var oDDL = xfa.resolveNodes("DropDownList1[*]");

// zero the fields accepting the counts

yesTotal.rawValue = null;

noTotal.rawValue = null;

naTotal.rawValue = null;

notTotal.rawValue = null;

// loop through the ddls to count answers

for (i = 0; i < oDDL.length; i ++) {

          if (oDDL.item(i).rawValue == 1) {

                    yesTotal.rawValue = yesTotal.rawValue + 1;

          }

          if (oDDL.item(i).rawValue == 2) {

                    noTotal.rawValue = noTotal.rawValue + 1;

          }

          if (oDDL.item(i).rawValue == 3) {

                    naTotal.rawValue = naTotal.rawValue + 1;

          }

          if (oDDL.item(i).rawValue == 4) {

                    notTotal.rawValue = notTotal.rawValue + 1;

          }

}

Avatar

Level 8

You could also use SOM predicates in the resolveNodes method and place a one liner in the calculate event of each total field:

this.rawValue=xfa.resolveNodes('DropDownList1.[$.rawValue=="1"]').length  //Counts all the fields named DropDownList1 with a value of 1

Kyle

Avatar

Level 8

Ya it was a recipe by Bruce that really open my eyes to the power of SOM predicates. I use to think it was just for binding data until I saw him use it in the resolveNodes method.

Better (and faster) than for loops.

http://cookbooks.adobe.com/post_Drop_Down_List_Control_with_auto_complete__Searcha-18402.html

Thanks Bruce!

Kyle

Avatar

Former Community Member

Thanks for the input.  Your idea seems to be the most straight forward, BUT running into a problem...

The 14 questions each have a flowed text comment field in addition to the drop down list box as well as fixed text references (this is an inspection checklist).  To make formatting easier, I put every thing in a table, each item is in it's own cell.  If the drop down list is in a cell in the table, the script does not work (even though they are wrapped in the same subform).  If I take the drop down list out of the table, it works fine.

Any thoughts?  

Avatar

Correct answer by
Level 8

You may need to expand the scope of the conditional expression to include the table.

Something like:

this.rawValue=xfa.resolveNodes('Table.Row.[Cell1.rawValue=="1"]').length;

That's without seeing your exact hierarchy.

Kyle

Avatar

Former Community Member

Thanks Kyle:

Still not sure how to deal with this, maybe if you look at the document at:

http://https://workspaces.acrobat.com/?d=rz73qoHxP01fckbOHCcC3Q

Thanks for your help...

Avatar

Level 8

OK...I did a few things...

I got rid of all your static rows since they were all identical and made one dynamic repeatable row.That should be easier to manage and edit. To adjust the number of rows and the text in each row go into the myLists scripting object and you will see it is relatively self explanatory how to make edits (just make sure the last entry doesn't have a comma at the end).

Also cleaned up some subforms you didn't need.

The code you had in your NumericField5 was out of scope. That means that NumbericField5 couldn't find the field Answer in the resolveNodes method because it was inside 3 other subforms (see code in pdf).

Changed the DropDown from Commit on Exit to Select.

http://www.fieldeffecttechnologies.com/AdobeForums/InspectionChecklist.pdf

Kyle

Avatar

Former Community Member

Hi Kyle:

If you have a chance can you take a look at the following thread and let me know what you think.

http://forums.adobe.com/thread/1321385

Thanks

Max