Setting response option based on question above it in a loop | XM Community
Solved

Setting response option based on question above it in a loop

  • 16 April 2019
  • 4 replies
  • 15 views

Userlevel 3
Badge +9
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.
icon

Best answer by Pete_L 16 April 2019, 16:57

View original

4 replies

Userlevel 3
Badge +9
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";}`
Userlevel 7
Badge +11
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.
Userlevel 3
Badge +9
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!
Userlevel 7
Badge +11
Ahh, gotcha. Yes, I didn't consider backing up not holding the correct word. Good call on the JS.

Leave a Reply