Skipping an entire row of a loop based on previous question | XM Community
Skip to main content
Hi Qualtrics community. I have an issue that I know how to resolve on other platforms but I'm running into a complicated way of addressing it here.



Long story short: Is there a way to skip the entire row of a loop if an earlier question does not meet certain criteria?



SCENARIO:

I have a loop of 50+ rows, each asking if you have been diagnosed with certain diseases/afflictions. Some of these are sex specific (i.e. don't ask about testicular cancer if the respondent wasn't born with testes). The sequence goes something like this:



Q1

Have you ever been diagnosed with ________?

Yes -> Go to Q2

No -> Go to next row

NULL -> Go to next row



Q2

At what age were you diagnosed with _______?



Q3

Do you still have _______?



SKINQ [show only to skin cancer, row 2]

"What kind were you diagnosed with?"



DIABETESQ [show only to diabetes, row 33]

"What kind were you diagnosed with?"





I configured skip logic on Q1 to be "If YES is NOT selected, skip to end of block"

I have the special questions at the end set to display if the current row is the appropriate disease/affliction



What I want to apply is some kind of pre-load action at Q1 to skip to the end of the block if 'current row = testicular cancer AND SEX<>01 (male)'. Is this possible????



Right now I'm applying display logic like this...DISPLAY IF:

Current Row <> Testicular Cancer

OR (new logic set)

Current Row = Testicular Cancer AND SEX = 01



But I have to apply that logic to all followups (Q2 and Q3 in above) as well. Is there some way to just skip the whole row?
@Pete_L,



Before your loop, add a multiple choice question with a choice for each loop. Add the appropriate display logic to each choice (e.g., For Testicular Cancer choice, display if SEX = 01). Hide the question with JavaScript. Then, in your loop & merge setup, base the loop on the displayed choices in your hidden MC question.
Thank you TomG. That sounds like it would work and I wouldn't have to chop up the existing loop too much.



I've created a demo to try this out but I'm stuck on the structure. This what you're picturing?



SEX

Page Break

SELECT_ROWS (the multi-select to be hidden)

Page Break

[BEGIN LOOP]



What method were you thinking for hiding the SELECT_ROWS variable? clickNextButton () with a super quick time to auto-move forward? I'm usually reluctant to do something like that.
Yes, that is the structure...you don't need the last page break since it is the end of a block.



Sometimes you can just hide the question with JS and avoid the click next depending on the order of your questions. In your case, it looks like you can't since sex is the previous question and you need that for your display logic. So, I would add a lot of padding to the top of the hidden question to push it off the bottom of the page so the respondent won't see it when it flashes by.
When you say hide with JavaScript you just mean change the css display:none via JavaScript on ready?



In my real situation there is a question that follows SEX, so I could put SELECT_ROWS on the same screen as that with display: none;
To hide a question with JS, add this it's JS:

```

Qualtrics.SurveyEngine.addOnload(function() {

jQuery("#"+this.questionId).hide();

});

```
This setup works in my demo. Thanks Tom!



Such an awkward workaround but I suppose it's what we have to work with right? 😃
Hey Tom I have a follow-up question. How would you proceed if the row selection variable has to be on the same screen as the question that determines it?



For example if it did adhere to what I had above:

1. SEX

2. SELECT_ROWS (display logic on the options)

3. LOOP (rows based on displayed from SELECT_ROWS)



I cannot put an auto-click on the SELECT_ROWS screen because the respondent would no longer be able to back up. I can't seem to put it on the same screen as SEX, either. Qualtrics pushes it to the next screen no matter what (I'm assuming the response display logic has something to do with it?).
> @Pete_L said:

> Hey Tom I have a follow-up question. How would you proceed if the row selection variable has to be on the same screen as the question that determines it?

>

> For example if it did adhere to what I had above:

> 1. SEX

> 2. SELECT_ROWS (display logic on the options)

> 3. LOOP (rows based on displayed from SELECT_ROWS)

>

> I cannot put an auto-click on the SELECT_ROWS screen because the respondent would no longer be able to back up. I can't seem to put it on the same screen as SEX, either. Qualtrics pushes it to the next screen no matter what (I'm assuming the response display logic has something to do with it?).



It can't be on the same screen. If you feel like you need it, add a descriptive text question to the same screen as SELECT_ROWS and use it to tell the respondent something that seems useful. 😉
What if we had some kind of function that on page unload (or onkeyup etc.) sets responses to the hidden multiselect? Or we won't be able to interact with it at all if it's set to hide?
> @Pete_L said:

> What if we had some kind of function that on page unload (or onkeyup etc.) sets responses to the hidden multiselect? Or we won't be able to interact with it at all if it's set to hide?



If you base your loop off selected choices instead of displayed choices in SELECT_ROWS you could do that. It would be more complex as you have to use JS to select the choices based on what is selected in SEX (and possibly other questions?). If the choices you want to carry into the loop are only based on SEX, then it wouldn't be too difficult. If you go this route use addOnPageSubmit.

Leave a Reply