I have a running if function that keeps returning the false parameter. This is from a select multiple field type, and I am not sure how to proceed. I have tried checking the options. Part of me wonders if its because I need to incorporate a select function and have tried but it always breaks everything. Anyone else have this problem and fixed it?
Here is list of choices and if.
Lower intertidal zone |
Mid intertidal zone |
Upper intertidal zone |
Supra tidal zone |
if(${tdzn}='Lower intertidal zone', 'LI', if(${tdzn}='Mid intertidal zone', 'MI', if(${tdzn}='Upper intertidal zone', 'UI', if(${tdzn}='Supra tidal zone', 'SU', 'null')))) |
The if statement formatting looks good, are you sure you're making your comparisons against the *coded* value of 'tdzn'?
It's not working because the question type is a Select Multiple. Which means the data in that field will have multiple comma separated values, so unless someone only selected 1 specific choice, ${field}= will never be true.
What you want is to check if a specific option has been selected in a field using selected(${question_one}, 'a').
Also, you need to be using the name field for your options, not the value. Spaces are not allowed in a Select Multiple name so it appears you are using the value.
Your if statement should look something like this:
if(selected(${tdzn},'Lower_intertidal_zone'), 'LI', if(selected(${tdzn}, 'Mid_intertidal_zone'), 'MI', if(selected(${tdzn}, 'Upper_intertidal_zone'), 'UI', if(selected(${tdzn}, 'Supra_tidal_zone'), 'SU', 'null'))))