Solved
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 by Pete_L
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";}`
View originalLeave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.