Lukas
Lukas

Reputation: 11

Prevent next button from working in Qualtrics

I have tried to make the working of the next button in Qualtrics conditional a certain variable value in javascript. If the condition is not met, I want to display an error message. However, with my current code (where the condition is not met) I see the error message briefly and then I progress to the next question anyways.

The javascript code is:

Qualtrics.SurveyEngine.addOnload(function()
{
 var test = 0;
$('NextButton').onclick = function (event) { 
        event.preventDefault();
        if (test==1){
        Qualtrics.SurveyEngine.navClick(event, 'NextButton');
        }
        else
        {
        document.getElementById("errorMessage").innerHTML = "Error message";
        }
        }
 });

And the html code is simply:

<div id="errorMessage"><span>This is a test</span></div>

I would really appreciate any help.

Thank you,

Lukas

Upvotes: 1

Views: 334

Answers (1)

Anthony Rivas
Anthony Rivas

Reputation: 962

Unfortunately, due to the way Qualtrics is setup, it is very difficult to hijack / override the next button's onclick event. The simplest workaround that I have found is to hide the actual next button, create a different button, and use that button for your expected actions.

Upvotes: 3

Related Questions