Skip to main content
kwooden626
Participating Frequently
July 8, 2018
Question

Get total from dropdown boxes

  • July 8, 2018
  • 1 reply
  • 383 views

Hello

I have a PDF form that has dropdown boxes in a column that has a text box at the bottom that I want to display a total sum based on the letter showing in the dropdown boxes.  If an "X" is displayed in the dropdown box, then I want it to be counted and included in the total at the bottom.  In the image below there are 4 "X's" displayed in the dropdown boxes and the total at the bottom of the boxes has "4".

I want to add a javascript to the "Total Hits" field that automatically adds the number of "X's" displayed in the dropdown boxes.  I will do the same thing for each Table (I, II, III, and IV).

Can someone please help me with this?

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
July 8, 2018

Let's say the names of the drop-down fields are "Dropdown1" to ""Dropdown7".

You can use this code to perform the calculation:

var fields = ["Dropdown1", "Dropdown2", "Dropdown3", "Dropdown4", "Dropdown5", "Dropdown6", "Dropdown7"];

var total = 0;

for (var i in fields) {

    if (this.getField(fields).valueAsString=="X")

        total++;

}

event.value = total;

kwooden626
Participating Frequently
July 8, 2018

try67 ,

Thank you so much!!  Your script worked like a charm and did exactly what I needed it to do.  I really appreciate your help.