How to shorten a calculation-syntax?

Hello,

This question is linked to another topic – feel free to have a look to see the context where it’s from.

https://community.kobotoolbox.org/t/how-to-setup-a-drop-down-list-with-country-code-flag-telephone-prefix/43819/5

But I think it probably deserves a separate thread :

The intention is to display a list of 244 countries in a dropdown-menu.

There is a working syntax for the calculation for an example of three items :

if(${Q2}= ‘C1’, ‘E1’, if(${Q2}= ‘C2’, ‘E2’, if(${Q2}= ‘C3’, ‘E3’, ’ ')))

but writing/repeating the <if(${Q2}= ‘C1’, ‘E1’,>sequence up to 244 times is a bit fastidious.

2023-08-16_Automatic_Answer_Select_Grid_Theme.53.3.1.xlsx (7.9 KB)

…so I was wondering if any syntax might be able to shorten the calculation-code, in order to streamline the expression of arrays, e. g. : if($[Q2]= ‘C1-C244’, ‘E1-E244’)

…Unfortunately, this piece of code doesn’t seem to work yet :

2023-08-16_Automatic_Answer_Select_Grid_Theme.53.4.0.xlsx (22.5 KB)

Is there any possibility to write some sort of short code for that purpose ? #array

Any hints would be much appreciated,

:slight_smile:

The following file makes it probably easier to check :

2023-08-16_Automatic_Answer_Select_Grid_Theme.53.4.0.xlsx (22.5 KB)

Selecting a Country/Flag should trigger the Dial-Code and vice versa.

#shortening + #triggering : How can I fix these points ?

@alienationfreez, it seems like you are trying to create a cascading select question. If yes, you should be able to do it by following this support article Adding Cascading Select Questions.

See your duplicated posting, please: How to keep Code short? - #8 by wroos.

1 Like