Move to a new question on 'Next' button click | XM Community
Skip to main content
Solved

Move to a new question on 'Next' button click


Forum|alt.badge.img
  • Level 1 ●
  • 11 replies
I am currently designing a survey where I have one question per page. There is a question where I have a javascript validation which displays an alert if the condition is not met. After the alert message is closed and next button is pressed, I need to move to a new question. And if the condition is met, I need to stay on the same question. So, is there a way by which I can move to a new question using the QID when next button is pressed, since I have only one question per page?

Best answer by TomG

You'll have to set an embedded data variable in your JavaScript then add display logic based on the embedded variable to the questions in between or put the questions in their own block and branch around them in the survey flow based on the embedded variable.
View original

6 replies

Samarth
Level 2 ●●
Forum|alt.badge.img+5
  • Level 2 ●●
  • 54 replies
  • July 13, 2018
Hi @srane, Not sure if I am getting the question correctly.Once the alert is closed you may use var $jq = jQuery.noConflict(); $jq('#NextButton').click(); to click on next button and proceed ahead. Please share your code for better understanding if this doesn't help. Regards, Samarth

mattyb513
Level 4 ●●●●
Forum|alt.badge.img+6
  • Level 4 ●●●●
  • 163 replies
  • July 13, 2018
> @Samarth said: > Hi @srane, > > Not sure if I am getting the question correctly.Once the alert is closed you may use > > var $jq = jQuery.noConflict(); > $jq('#NextButton').click(); > > to click on next button and proceed ahead. Please share your code for better understanding if this doesn't help. > > Regards, > Samarth Note that instead of changing jquery to no conflict mode you can simply reference it as ‘jQuery’

Forum|alt.badge.img
  • Author
  • Level 1 ●
  • 11 replies
  • July 13, 2018
Actually, I don't need to go to the next question on next button click. I need to move to a question which is around 5-6 questions further ahead. So, when the alert pops up and the user closes it(using 'OK' button or 'x' button of the alert box), I need the user to skip 5 questions and directly move to the sixth one. In short, if alert pops up, skip 5 questions and move to 6th question, else display the next question. I need some sort of branching logic or a javascript that jumps to the QID of the question directly.

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5926 replies
  • Answer
  • July 13, 2018
You'll have to set an embedded data variable in your JavaScript then add display logic based on the embedded variable to the questions in between or put the questions in their own block and branch around them in the survey flow based on the embedded variable.

mattyb513
Level 4 ●●●●
Forum|alt.badge.img+6
  • Level 4 ●●●●
  • 163 replies
  • July 13, 2018
You might consider using the built in validation with skip logic as well. It's unclear from what you've presented whether JavaScript is truly necessary here.

Forum|alt.badge.img
  • Author
  • Level 1 ●
  • 11 replies
  • July 13, 2018
Using embedded data in conjunction with display logic has solved the problem. I am setting an embedded variable using javascript when the alert pops up and then checking its value in the display logic of each question to decide on whether to display that particular question (Just as @TomG has suggested).

Leave a Reply