Js to change text on next button of next block based on selection done in NPS q in current block | XM Community
Skip to main content

I just wanted to check if anybody has a js code to change the text on next button based on the selection done in a question on different page.. for example if on page 1 nps question is rated less than 4 then the next button on the next page should say submit and survey should end but if the selection is more than 4 than the next button on next page should say next and move to the remaining questions. Thank you in advance!!

Hi there,

the code could look something like that:

Qualtrics.SurveyEngine.addOnload(function()
{
let recodeValue = Number("${q://QID1/SelectedChoicesRecode}");
let nextButtonText
if (recodeValue <=4){
nextButtonText = "Submit";
}else{
nextButtonText = "Submit";
}
var lastLoopOnly = true; // if the question is in a loop

if(!lastLoopOnly || "${lm://CurrentLoopNumber}" == "${lm://TotalLoops}") {
let nb = jQuery('#NextButton');
nb.val(nextButtonText);
nb.attr('title', nextButtonText);
}
});

best regards

Rudi


Hi Thank you for your reply
I tried this code and it worked on onload
if ("${q://QID20/SelectedChoicesRecode}" == "1" || "${q://QID20/SelectedChoicesRecode}" == "2" || "${q://QID20/SelectedChoicesRecode}" == "3" || "${q://QID20/SelectedChoicesRecode}" == "4" )
 { 
  jQuery("#NextButton").attr({value:"Submit",title:"Submit"});
      }

else{
jQuery("#NextButton").attr({value:" → ",title:"→"});
}


Hi,
sorry for the error on the second nextButtonText. this should have been next or in your case -> ;-)
anyways I am glad that your adopted code works

Best regards

Rudi


Leave a Reply