Move to a new question on 'Next' button click | XM Community
Skip to main content
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?
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
> @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’
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.
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.
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.
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