Conditional display upon iteration in loop

dschreijdschreij AmsterdamCommunity Member Qubie ✭

Conditional display upon iteration in loop

Hi, I was wondering if someone could help me with the following:
I have a loop & merge item of which the order is randomized. I'd like to show a descriptive text question in all iterations except for the first (i.e. "You are going to answer these sets of questions another time ..."). Is there I way I can 'tap into' the loop counter using display logic? The only option I found in there is selecting a specific loop item in which the question should be displayed, but the fact that my loop is randomized makes this unusable.

Answers

  • Pete_LPete_L Community Member Qubie ✭
    edited October 24

    I'd suggest using JavaScript. Here's what I'm picturing:

    1 - Create an embedded data field in your survey flow and set it default to 1.
    2 -On the screen the text displays on, add something like a span to put the display text into:

    <span id="descText">&nbsp;</span>

    3 -onReady you do something like this:

    var loopnum = "${e://Field/loopnum}";//Embedded data loop counter
    if(loopnum<2) { //If this is the first loop then...
    document.getElementById('descText').innerHTML = "";
    } else { //Otherwise this is not the first loop so we display the text...
    document.getElementById('descText').innerHTML = "You are going to answer these sets of questions another time...";
    }

    4 - onPageSubmit at the end of the loop you will want to do something like this to increment the counter:

    Qualtrics.SurveyEngine.addOnPageSubmit(function()
    {
    var loopnum = "${e://Field/loopnum}";
    loopnum = loopnum+1;
    Qualtrics.SurveyEngine.setEmbeddedData("loopnum", loopnum);
    });

  • dschreijdschreij AmsterdamCommunity Member Qubie ✭

    Thanks, I already solved this with a similar solution, without using javascript but some smart usage of embedded data fields.

Sign In to Comment