Hi Qualtrics users,
I have a question which I thought I might throw out to the brains trust to see if anyone is able to help.
As part of designing a survey, my team and I would like to include a 'withdraw from survey' button. I have been using this forum to include the button (link), but unfortunately it is not working as intended. As it stands, the withdraw button and hidden question function (see below) only seem to work on the first page of the survey - both when in preview mode and also when filling out the live survey.
The first piece of code is used to create the withdraw button in the footer, using "Look & Feel":
The second piece of code is used to create a hidden question on each survey page that is activated when the withdraw button in the footer is selected.
Qualtrics.SurveyEngine.addOnload(function() {
var that = this;
var endBtn = document.getElementById("EndNow");
function skip() {
that.setChoiceValue(1, true);
that.clickNextButton();
};
endBtn.addEventListener("click", skip);
});
Does anyone have any thoughts on why this might be the case, or what could possibly be done to remedy it?
A possible reason my colleague and I think the error is occurring is inclusion of "onload" in the second piece of code.
We have played around with each line of the latter code: un-hiding the question to see if it's been triggered when "withdraw" is selected and so on. It appears that the first response in the hidden question isn't being selected after the first page/block and so the code isn't being fully executed. We noticed that when moving through the survey, the webpage isn't being loaded and reloaded when you press the "next button," rather the webpage is simply progressing onto the next page of the survey. We are therefore wondering whether the first line of the second piece of code needs to be amended? As you'll see, it says "Qualtrics.SurveyEngine.addOnload(function() { " and the function is being executed on each page load. However, if the page isn't continuing to load with each subsequent page, might the code only be executed on the first page/first load?
Thanks so much for reading.
Page 1 / 1
The second piece of code is used to create a hidden question on each survey page that is activated when the withdraw button in the footer is selected.\\
This is where the problem is. You need to manually create the question on each page and this JS to it.
Thanks ahmedA! Do you mean that we need to manually create the hidden question on each page? We have already done that, but the problem persists.
Yes. That's what I had meant. But since that isn't working, try changing the
addonloadto
addonReady.
While, the logic at the end of your question, related to page loads in not entirely accurate, because each time you click the next button, a new page is loaded. Because its being done using JS, we don't see the URL change. Its possible that your footer is being overwritten after loading.
Thank you so much, ahmedA! This has been really helpful.
Alternatively, you can also move your button to the question HTML and hide the choices by adding this line
this.getChoiceContainer().hide();in JS. This will show the button, but not the options, moving the withdraw button a little higher.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.