Vignette study with java script | XM Community
Skip to main content

Hi, I’m new to using java script in Qualtrics and I have a question.

I’m running a study where participants are randomly allocated to read one of 16 vignettes. Of course, I could set this up using the survey builder and survey flow, but I would like to use code - this is a pilot study for a larger experiment with over 500 vignettes, which would be too complicated to set up manually.
What I think I need to do is to set embedded data fields with variable names for each vignette, and then tell Qualtrics the corresponding vignette text for each name. Next, I can use the survey flow to randomly assign one vignette to each participant. 
I have never used java script before, so this is the code I scrambled together (it’s probably totally wrong): 
 

Qualtrics.SurveyEngine.addOnload(function() {
    // Get the value of the selected variable from embedded data
    var selectedVariable = "${e://Field/SelectedVariable}";

    // Define the vignettes with their corresponding text
    var vignettes = {
        "aAA1BB1AB1BA1": "Text for vignette 1...",
        "aAA1BB1AB1BA0": "Text for vignette 2...",
        // Add more vignettes as needed
    };

    // Get the text for the selected vignette based on the selected variable
    var selectedVignetteText = vignettesaselectedVariable];

    // Set the text of the question to display the selected vignette
    this.getQuestionTextContainer().innerHTML = selectedVignetteText;
});
 

Could somebody help me with this?

Be the first to reply!

Leave a Reply