Reputation: 243
Problem: How can you capture a pre-determined or static text value based on what choice a user makes from a multiple choice menu on a survey?
Example: Suppose you have the following basic setup:
I have four text statements that correspond to options 1-4 (e.g., "Statement corresponding to Option 1", "Statement corresponding to Option 2", etc.). If the user chooses, say, Option 1 from the sample_options
field, then I would like to capture the text value of the pre-prepared statement in the option_statement
field. The user should not be able to alter the captured text statement (e.g., maybe hide the field using the @HIDDEN
action tag).
Attempt: It seemed like this might be a problem that could be resolved with action tags, namely the @DEFAULT
one, but I have been unable to do this. I also thought about trying to use a calculated field instead of a text field for option_statement
, but calculated fields must return numeric values:
This seems like a problem that should be somewhat straightforward to tackle, but I have been baffled by just how hard it seems to be to simply capture static text in one field based on a user's selection in another field.
Upvotes: 1
Views: 1579
Reputation: 868
If I understand the question, you want to select a text string from a list of (in this case) 4 options, depending on the user selecting a choice from a radio/dropdown?
Probably the easiest method is to use @CALCTEXT
(if you are on a sufficiently recent version), which allows you to conditionally populate a text field, i.e.:
@CALCTEXT(
if([sample_options] = 1, "This is the label for option 1",
if([sample_options] = 2, "This is the label for option 2",
if([sample_options] = 3, "This is the label for option 3",
if([sample_options] = 4, "This is the label for option 4", "This is an else value")
)
)
)
)
But if you do not have @CALCTEXT available to you, you can do this with a @DEFAULT
, by constructing another radio field (@HIDDEN
if you like) on a separate page or instrument (as @DEFAULT
needs the value to exist in the database on page load, and so does not work dynamically on the page), with your four labels as the options with the same choice codes as your [sample_choices]
field. For example:
1,This is the label for option 1
2,This is the label for option 2
3,This is the label for option 3
4,This is the label for option 4
And annotate it with:
@DEFAULT='[sample_choice]'
Thus if a user selects 3 for [sample_choice]
and proceeds to the page or instrument that has the label field, the @DEFAULT
tag will automatically select choice 3 from the label field, which can then be stored in the dataset and piped into an email, onto the page, or whatever.
Upvotes: 1