Expand my Community achievements bar.

## Totals from drop downs

Level 1

I have a table with a number of drop down answers (Yes, No)

Each of these has assigned a value (yes = 1, No = 2)

I have another column where I would like to present a 'score' by totalling these columns or row.

So lets say I have a dropdown box called 'drop1' and a numeric field called 'numericfield1'

I tried creating a numeric field in the table, then using FormCalc I've shown 'calculate*' then tried 'sum drop1' and lots of other variations.

Can anyone explain what I am doing wrong?

Many thanks,

~ Paul

7 Replies

Level 10

Hi Paul,

Because you have assigned the values to the dropdown, you can include the following in the calculate event of the numericfield:

this.rawValue = drop1.rawValue + drop2.rawValue + drop3.rawValue;

or in Formcalc:

\$ = drop1 + drop2 + drop3

Good luck,

N.

Level 1

Hi

Thank for your reply. I entered the FormCalc you gave, and get the error:

script failed .....

.......

Error: accessor 'drop1' is unknown.

Level 10

Hi,

The error looks like that there are several copies of drop1, e.g. drop1[0], drop1[1], drop1[2], etc.

If the table has a fixed number of rows, then set the object name for each dropdown object. The Formcalc can then refer to each object.

If the table is dynamic and the user can add additional rows, then you will need to loop through each occurrence of the drop1 object and add this.

Attached are some basic examples of a straight calculation and a loop.

Hope that helps,

N.

Former Community Member

It has been a while since I have used FormCalc so you can double check the help.

But....

If you have named a field the same e.g. Drop1  and have multipel fields Drop1[0], Drop1[1], Drop1[2].... etc. Then you have multipel instances.  With formCalc you can simple sum them by saying  \$ = sum(Drop1[*])  and it will loop through all instances of Drop1 to some.  Once again just double-check the syntax (e.g Sum or sum, etc.)

Level 1

Thank you all for your help.

I do not seem to have different instances of 'drop1'.

In the binding tab the name = drop1   There is a square with 0 after it, is that suffix? The same name is found in the hierarchy too.

Also in binding, the text for the drop down is Yes or No, and I have entered values 1 and 2 respectivly.

Is that right??

~ Paul

Level 10

Hi Paul,

Where you see [] after an object name with a number inside the square brackets; that means that there is another object with the same name. The index is zero based, so 'drop1[0]' is the first instance of an object called 'drop1'.

'drop1[1]' is the second instance and so on.

Short answer is that you do have multiple instances of the same name. This can complicate scripting, but it is still possible. Have a look at the sample above.

In relation to the dropdown lists, you can specify what ever values you want:

Yes = 1; No = 0

Yes = 1; No = 2

As long as you are consistant and script your objects based on the specified values.

Hope that helps...

Niall

Level 1

Huge thank you !

The world is much clearer now  :-)