I have a 2-option MC question inside a L&M block. If participants click the green button, I want to show them (in page) a payout (e.g., you win $4 or $0). I have a counter (embedded data set via JS) that records each time someone clicks the green button.
What I need: The first time someone clicks the green button then display the field ${e://Field/g1}, the second time they click the green button then display the field ${e://Field/g2}, …
Right now, I’m trying to accomplish this in two steps:
- Actually displaying the field ${e://Field/current_payout_green} in the survey
- Trying to update that field each time the green button is clicked via the following JS:
Qualtrics.SurveyEngine.addOnReady(function() {
var currentGreenCounter = parseInt("${e://Field/green_counter}", 10);
if(jQuery("#"+this.questionId+" input"choiceid='2']")) {
// increment counter
currentGreenCounter += 1;
Qualtrics.SurveyEngine.setEmbeddedData('green_counter', currentGreenCounter);
//Update the display embedded data
var updated_visual_green = "${e://Field/g" + currentGreenCounter+"}";
Qualtrics.SurveyEngine.setEmbeddedData('current_payout_green', updated_visual_green);
}
});
(Note: Prior to this focal block, I initialize the ED field `current_payout_green` as `${e://Field/g1}`)
This works the first time the green button is clicked (because I’ve hard-coded this to be ${e://Field/g1}) but does not work any time thereafter -- the field is blank.
How can I use JS to update the ED field `current_payout_green` upon clicking the green button (option 2) -- effectively setting it to `${e://Field/g" + currentGreenCounter+"}`?
Thanks!