NPS (1 TO 11) | XM Community
Skip to main content

NPS question from 0 to 10 leabelled as 1 to 10 and NA. but when i hit back button my answers go 1 step back like 10 becomes 9 and 9 as 8 and so on. How can i changes this>

 

Qualtrics.SurveyEngine.addOnload(function()
{
    /*Place your JavaScript here to run when the page loads*/

var selChoiceLoad = this.getSelectedChoices();
var selChoiceNumLoad = parseInt(selChoiceLoad) - 1;
this.setChoiceValue(selChoiceNumLoad, true);

});

Qualtrics.SurveyEngine.addOnReady(function()
{
    /*Place your JavaScript here to run when the page is fully displayed*/
jQuery("#"+this.questionId+"-0-label").html("1");
jQuery("#"+this.questionId+"-1-label").html("2");
jQuery("#"+this.questionId+"-2-label").html("3");
jQuery("#"+this.questionId+"-3-label").html("4");
jQuery("#"+this.questionId+"-4-label").html("5");
jQuery("#"+this.questionId+"-5-label").html("6");
jQuery("#"+this.questionId+"-6-label").html("7");
jQuery("#"+this.questionId+"-7-label").html("8");
jQuery("#"+this.questionId+"-8-label").html("9");
jQuery("#"+this.questionId+"-9-label").html("10");
jQuery("#"+this.questionId+"-10-label").html("Geen antwoord").css({"padding":"1px"});
});

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

});


Qualtrics.SurveyEngine.addOnPageSubmit(function(type) {
 if(type == "next") {
 var selChoice = this.getSelectedChoices();
 if(selChoice.length > 0) { // Ensure a choice is selected
 var selChoiceNum = parseInt(selChoicee0]); // Use the first selected value
 this.setChoiceValue(selChoiceNum, true);

 jQuery("#"+this.questionId+"-"+selChoiceNum+"-label").css({
 "background": "hashtag#f1f1f1",
 "border": "none",
 "color": "#000000"
 });
 }
 }
});

Hi ​@PeeyushBansal,

Have you given a thought to use a Multiple choice question type instead?

You can use 1 to 10 scale and NA as an option and also manage this on Dashboard side.
You can align them horizontally to make it look like an NPS scale.
 


Yes but in moblile the labels will get vertical for MS question.


You can use 11 columns format instead of horizontal, they’ll stay linear on mobile too.

As for why your answer diminishes every time you hit back, it’s because of your addOnLoad function: every time you load the page, you retrieve the selected choice and substract 1, then set that choice value to true.


You can use 11 columns format instead of horizontal, they’ll stay linear on mobile too.

As for why your answer diminishes every time you hit back, it’s because of your addOnLoad function: every time you load the page, you retrieve the selected choice and substract 1, then set that choice value to true.

Is there a way to avoid it, I want to show horizontal as have many such questions on 1 page.


@Tom_1842’s code is good by the way, you just have to test it in a live survey, not with the preview :

It will also readjust the value back to what the respondent selected if the back button is used, but test with live link not a preview:

 


Yes but in moblile the labels will get vertical for MS question.

You can use the columns option to handle this if that’s easier than the JS.


Please refer this post for the best possible setup.


Leave a Reply