Turn off the next button | XM Community
Skip to main content

Turn off the next button

  • September 13, 2022
  • 9 replies
  • 47 views

Forum|alt.badge.img+8

Hi
I need to turn off the next button until the first question is answered.
I need the button to be displayed but in a different color and not active.


9 replies

mmoore
Level 2 ●●
Forum|alt.badge.img+9
  • Level 2 ●●
  • September 14, 2022

Could you just require a response to the first question using the built-in Response Requirements?


Forum|alt.badge.img+8
  • Author
  • QPN Level 4 ●●●●
  • September 14, 2022

I already have this question as mandatory, however due to client requirements i also need to generate this change.


Tom_1842
Level 8 ●●●●●●●●
Forum|alt.badge.img+28
  • Level 8 ●●●●●●●●
  • September 14, 2022

Hi there, try adding the below to the Onload section of your first question's JavaScript:
jQuery("#NextButton").css('background-color','red');

this.disableNextButton();

QBody = document.querySelector('.QuestionBody');

QBody.addEventListener("click", () => {
    this.enableNextButton();
});


Forum|alt.badge.img+8
  • Author
  • QPN Level 4 ●●●●
  • September 14, 2022

Hi Tom_1842
i am getting this error:
Invalid JavaScript! You cannot save until you fix all errors: Unexpected end of input.
Not sure why 😔


Tom_1842
Level 8 ●●●●●●●●
Forum|alt.badge.img+28
  • Level 8 ●●●●●●●●
  • September 14, 2022

Erikahuer Hmm, you might be missing a });, try replacing the entire question JS with the below:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/

jQuery("#NextButton").css('background-color','red');

this.disableNextButton();

QBody = document.querySelector('.QuestionBody');

QBody.addEventListener("click", () => {
this.enableNextButton();
});    

});


Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/

});


Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/

});


Forum|alt.badge.img+8
  • Author
  • QPN Level 4 ●●●●
  • September 14, 2022

Sadly it is not working :/


Tom_1842
Level 8 ●●●●●●●●
Forum|alt.badge.img+28
  • Level 8 ●●●●●●●●
  • September 14, 2022

Erikahuer Hmm, it is on my end... what question type are you using? If you can provide more details about your setup, or even a QSF, I might be able to see if I can replicate and fix


Forum|alt.badge.img+8
  • Author
  • QPN Level 4 ●●●●
  • September 14, 2022

I am using an NPS question
Screen Shot 2022-09-14 at 15.05.06.png


Tom_1842
Level 8 ●●●●●●●●
Forum|alt.badge.img+28
  • Level 8 ●●●●●●●●
  • September 14, 2022

Ah okay, the code I posted only works when the Question Body area is clicked, so not exactly what you were looking for anyway.
I found a thread that I think will help though. In that, rondev provides JS that will do what you want when a radio button is selected, like for an NPS question. Below for reference:
jQuery("#NextButton").css('background-color','red');

this.disableNextButton();
   
    this.questionclick = function(event,element)
    {
        if (element.type == 'radio')
        {
            this.enableNextButton();
        }
    }