how to redirect the "next" button to different question or block based on the choice of current question? | XM Community
Skip to main content
Solved

how to redirect the "next" button to different question or block based on the choice of current question?


Forum|alt.badge.img+1

Hi experts,

 

I am thinking about the code the survey with javascript and html in order to re-direct the “next page” button.

 

How to do that for a simple example?  The question in the page is: do you want to upload more items? There are two choice: one is yes, the other is no. If the answer is yes, the “next page” button will go to a block named “uploading block” If the answer is no, the “next page” will go to the block named as “exit block.”

 

I understand it can be done with a built-in branch function. But I need to learn to do it in this simple example. So that I can build more complicated ones later on.

Best answer by TomG

@YXC,

You can use JavaScript to set an embedded data field if the ‘Yes’ choice (choice id 1) is chosen:

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
	if(this.getSelectedChoices()[0]=="1") Qualtrics.SurveyEngine.setEmbeddedData("EndLoop","1");
});

Add display logic to all the questions in your loop to display if EndLoop Is Not Equal to 1.

View original

3 replies

Aggarwal
Level 4 ●●●●
Forum|alt.badge.img+15
  • Level 4 ●●●●
  • 134 replies
  • February 4, 2025

You can apply branch in survey flow and apply logic at block level. It is easy to manage it at survey flow levels. 


Forum|alt.badge.img+1
  • Author
  • 1 reply
  • February 4, 2025

It could be done by branching in this simple case. But if I need a little more, it will be difficult. For example, if I need to create a loop on top of this, I may need to create custom button to do so.

 

For example, in a page, I have three questions, the first two questions are file upload and text question, the last question ask if there is another upload. If the answer to the last question is “yes”, then the “next” button re-direct to the same page. If the answer to the last question is “no”, the the survey move to the next block. In this case, the javascript  may be needed.


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5909 replies
  • Answer
  • February 4, 2025

@YXC,

You can use JavaScript to set an embedded data field if the ‘Yes’ choice (choice id 1) is chosen:

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
	if(this.getSelectedChoices()[0]=="1") Qualtrics.SurveyEngine.setEmbeddedData("EndLoop","1");
});

Add display logic to all the questions in your loop to display if EndLoop Is Not Equal to 1.


Leave a Reply