For a question, I have 4 choices (alpha, beta, gamma, delta) displayed in random order through choice randomization. I want the displayed order of these choices to be captured in embedded data fields, to be used later in the survey (to study how order in which choices are displayed affects recall, for example). For instance, if the choices were displayed in the order
beta gamma alpha delta
I want embedded data fields pos_beta = 1, pos_gamma = 2, pos_alpha=3 and pos_delta=4.
If they were displayed
gamma alpha beta delta
I want embedded data fields pos_gamma = 1, pos_alpha = 2, etc
Easiest way to implement this? (Also, could the answer be generic enough to capture if the choices had random text around the keywords – "blah blah gamma blah blah" etc?)
I guess I have to loop through each choice using some version of:
jQuery("#"+this.questionId+" [type=radio]").each(function(i) {
}
and within the loop check sequentially if "alpha", "beta" etc is contained in the choice text, and then assign i to the corresponding embedded data field. Is this approach correct, and if yes, how do I check if a specific substring is contained in the choice text?
Thanks in advance!
2
Answers
If you want to add data attributes to
<option>
elements, based on their original potion in the source array, you can useindexOf
to find the original index.The following code above will construct something similar to below:
You can do this:
You can decouple variable names from the displayed choice labels by setting them using ‘Recode Values’.