Setting response option based on question above it in a loop

Pete_LPete_L Community Member Qubie ✭

Setting response option based on question above it in a loop

Hi Qualtrics Community,

I've got another wacky situation I'm trying to deal with. I need to set a dynamic gender text-fill (he/she) based on the question immediately before hand, inside a loop. I know how to do this in other platforms but Qualtrics is a bit trickier. Below is the scenario:

Q1 [text/numeric]
How many siblings do you have?

[Looped block based on Q1 - max 99 iterations]
LoopQ1 [radio]
What sex was this sibling assigned at birth?
1: Male
2: Female
3: Intersex

LoopQ2 [text/numeric]
How old is [he/she/your sibling] today?

I've been trying a few different things out but this is pretty tricky because it's in a loop. My first instinct was to create a hidden text-fill question between LoopQ1 and LoopQ2 that sets its value based on LoopQ1, but I'm having trouble creating JavaScript that can dynamically set itself based on a question on the same screen.

My attempt so far has to use some jquery to search for "ends with" but it's been kind of wonky. Any ideas how you would go about doing the above situation?

Criteria- it's in a loop and the respondent MUST be able to back up to previous questions.

Best Answer

  • Pete_LPete_L Qubie ✭
    Accepted Answer

    Came up with a solution.

    1. Created a text question below LoopQ1 (type text) and hid it using JavaScript.
    2. Parsed out the loop number using JavaScript
    3. Created a variable to store the text question ID, something like:

    var loopnumber = parseInt("${lm://CurrentLoopNumber}"); var Qanswer= this.getChoiceAnswerValue(); var textID = "QR~" + loopnumber + "_QID3";
    Then I set the value of the text input based on the response value. Like this...

    if(Qanswer==1){document.getElementByID(textID).value="he";} else if (Qanswer==2) {document.getElementByID(textID).value="she";} else {document.getElementByID(textID).value="your sibling";}

Answers

  • JenCXJenCX Broomfield, COCommunity Member Superuser ✭✭✭✭
    edited April 16

    As far as I know, you could also do this with an embedded data field that you set within the loop based on the answer to LoopQ1 within the loop. Based on what I know, each time the loop would iterate, the embedded data field would be updated. You could then use the embedded data field with piped text in LoopQ2, just need to have a page break in between LoopQ1 and LoopQ2.

  • Pete_LPete_L Community Member Qubie ✭

    Thank you @jpardicusick. That's how I was solving all the non-looped versions of this problem. They do want the gender text-fill to be permanent so that you could back up and see he/she/your sibling based on the correct row though, so this more complex solution was my best bet!

  • JenCXJenCX Broomfield, COCommunity Member Superuser ✭✭✭✭

    Ahh, gotcha. Yes, I didn't consider backing up not holding the correct word. Good call on the JS.

Sign In to Comment