Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Counting the number of values selected in a list box

Avatar

Level 2

I'm trying to add a counter to a form that tells the user how many values have been selected from a list box... I tried adding a FormCalc formula to a calculate event in the "counter" field as follows:

count(form1.#subform[0].ListBox1.rawValue)

But for some reason it's not adding them up. It only gives me a value of 0 when none are selected, or 1 where any number of selections are made.

Can anyone help me out?

Thanks in advance

1 Accepted Solution

Avatar

Correct answer by
Level 8

Try putting this in the calculate event of your counter field:

var num=0;

for (var a=0;a<ListBox1.items.nodes.length;a++){

if (ListBox1.getItemState(a))

  num++;

}

this.rawValue=num;

Exit the list box and the field will calculate.

Kyle

View solution in original post

2 Replies

Avatar

Correct answer by
Level 8

Try putting this in the calculate event of your counter field:

var num=0;

for (var a=0;a<ListBox1.items.nodes.length;a++){

if (ListBox1.getItemState(a))

  num++;

}

this.rawValue=num;

Exit the list box and the field will calculate.

Kyle

Avatar

Level 2

Excellent, thank you very much.