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

NPS (1 TO 11)

  • February 25, 2025
  • 7 replies
  • 47 views

PeeyushBansal
Level 6 ●●●●●●
Forum|alt.badge.img+39

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(selChoice[0]); // Use the first selected value
 this.setChoiceValue(selChoiceNum, true);

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

Best answer by PeeyushBansal

Please refer this post for the best possible setup.

View original

7 replies

Sowrabh1993
QPN Level 5 ●●●●●
Forum|alt.badge.img+15
  • QPN Level 5 ●●●●●
  • 112 replies
  • February 25, 2025

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.
 


PeeyushBansal
Level 6 ●●●●●●
Forum|alt.badge.img+39
  • Author
  • Level 6 ●●●●●●
  • 1143 replies
  • February 25, 2025

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


vgayraud
QPN Level 5 ●●●●●
Forum|alt.badge.img+48
  • QPN Level 5 ●●●●●
  • 357 replies
  • February 25, 2025

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.


PeeyushBansal
Level 6 ●●●●●●
Forum|alt.badge.img+39
  • Author
  • Level 6 ●●●●●●
  • 1143 replies
  • February 25, 2025
vgayraud wrote:

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.


vgayraud
QPN Level 5 ●●●●●
Forum|alt.badge.img+48
  • QPN Level 5 ●●●●●
  • 357 replies
  • February 25, 2025

@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:

 


Sowrabh1993
QPN Level 5 ●●●●●
Forum|alt.badge.img+15
  • QPN Level 5 ●●●●●
  • 112 replies
  • February 25, 2025
PeeyushBansal wrote:

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.


PeeyushBansal
Level 6 ●●●●●●
Forum|alt.badge.img+39
  • Author
  • Level 6 ●●●●●●
  • 1143 replies
  • Answer
  • February 27, 2025

Please refer this post for the best possible setup.


Leave a Reply