These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

How to count values in a drop-down list

jfoster
Registered: Mar 29 2011
Posts: 7
Answered

How would one go about getting a count of the values chosen from a drop-down list? I have 18 drop-down lists that all have the same options: Infant, Toddler, Preschool and School Age. I have a total box at the bottom for each of these areas and would like to get a count of how many boxes are filled in with each choice.
 
For example, if 12 boxes are chosen as Infant, 2 as Toddler, 1 as Preschool and 3 as School Age, I would like my results box to count only the 12 Infant choices and give me 12 as a result. I need to repeat this process across 3 other boxes to count the number of Toddler, Preschool and School Age choices as well, but I'm sure I can merely copy the formula over.
 
Here is the code I am currently using, but it counts all the fields that have any value in them, not just the ones with the Infant value.
 
foreach Infant in (topmostSubform.Page3[*]) do
Count(RoomAge[*])
endfor
 
Any help is appreciated, please let me know if you need more information.

My Product Information:
LiveCycle Designer, Windows
jfoster
Registered: Mar 29 2011
Posts: 7
I forgot to mention I am using FormCalc.
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Hi,

this can be done with a for loop.

  1. var sA = 0
  2. var sB = 0
  3. var sC = 0
  4. for i=0 upto RoomAge.all.length -1 do
  5. if (RoomAge[i].rawValue eq "AAA") then
  6. sA = sA + 1
  7. elseif(RoomAge[i].rawValue eq "BBB") then
  8. sB = sB + 1
  9. elseif(RoomAge[i].rawValue eq "CCC") then
  10. sC = sC + 1
  11. endif
  12. endfor
  13. $host.messageBox(Concat("ValueA: ", sA,"\u000dValueB: ", sB,"\u000dValueC: ", sC))

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

jfoster
Registered: Mar 29 2011
Posts: 7
I still cannot get it to work. I'm not terribly familiar with coding, but have dabbled in it some. I've uploaded my document to Acrobat.com. If you have time, I would greatly appreciate your time in looking at what I'm attempting.

https://acrobat.com/#d=Y1qxZHAm9nPljQe7pgg6nw
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Your link seems to be inactive, I cannot download your form.

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

jfoster
Registered: Mar 29 2011
Posts: 7
It works for me when I copy/paste it. Is there a way to paste a working URL into this forum?
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Make sure you have shared the form, I still get no access to it.

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

jfoster
Registered: Mar 29 2011
Posts: 7
OK, thank you for your patience, I wasn't aware that step was necessary. It is now shared.

https://acrobat.com/#d=Y1qxZHAm9nPljQe7pgg6nw
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Accepted Answer
Hi,

you only missed to assign the calculated value to your text field.
Just put this script into the calculate:Event.

  1. var nCount = 0
  2.  
  3. for i=0 upto RoomAge.all.length -1 do
  4. if (RoomAge[i].rawValue eq "Infant") then
  5. nCount = nCount + 1
  6. endif
  7. endfor
  8.  
  9. $ = nCount

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

jfoster
Registered: Mar 29 2011
Posts: 7
Works beautifully now, thank you so much.
rohani
Registered: Apr 6 2011
Posts: 1
Hi I'm having a similar issue...

I'm working on a form that dynamically adds and removes rows from a table.

One of the columns in the table has a drop-down list which allows the user to select either "Phone, Fax or ADSL" as a choice of Line Type.

I need a formula to calculate the number of instances of each Line Type at the end of the user input.

I have adapted the code to the following:

var nCount = 0

for i=0 upto Row1[*].Type.all.length -1 do
if (Row1[*].Type[i].rawValue eq "Phone") then
nCount = nCount + 1
endif
endfor

$ = nCount

The code is only working for the first row in the table. Any ideas for making this work in a dynamic table?

Thanks :)


radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Hi,

you need to count the present number of rows not the number of cells.

  1. var nCount = 0
  2.  
  3. for i=0 upto Table._Row.count -1 do
  4. if (Table.Row[i].Type.rawValue eq "Phone") then
  5. nCount = nCount + 1
  6. endif
  7. endfor
  8.  
  9. $ = nCount

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

katmetz
Registered: Nov 29 2011
Posts: 7
I am trying to do a similar thing, but I have no idea what i am doing. I tried using the formulas you supplied in other posts, but I can't get it to pull from my drop downs. I am creating a timecard. It has 7 "Types" to choose from Regular, Holiday, PTO, etc.. for each day of the pay period. I am trying to come up with a summary of how many hours were worked in each Type.

I applied the following formula to the totals text box(nCount1). (example for Regular (type) hours)

var nCount1=0

for i=0 upto Type.all.length -1 do
if (Type[i].rawValue eq "Regular") then
nCount1 = nCount1 + 8
endif
endfor

I plan to use this formula for each totals text box for each different type. The formula has no errors, but it will not change the number when I select the drop downs.

I hope this made sense..
Thanks for any help.

K. Harrison