NPS question | XM Community
Skip to main content
Solved

NPS question

  • October 16, 2023
  • 5 replies
  • 104 views

Forum|alt.badge.img+1

Good morning,

I have a question in nps which goes from 0 to 10 in my question 1 "Q1". I created a second question without using display logic so that if I put in q1 between 0 to 6 it displays me in a paragraph "sorry", 7 to 8 "good" and 9 to 10 "very good " with js code but it's the first time I'm using it and I'm a little lost. Thank you very much for your help.

Sincerely

Best answer by Nam Nguyen

Good morning,

I have a question in nps which goes from 0 to 10 in my question 1 "Q1". I created a second question without using display logic so that if I put in q1 between 0 to 6 it displays me in a paragraph "sorry", 7 to 8 "good" and 9 to 10 "very good " with js code but it's the first time I'm using it and I'm a little lost. Thank you very much for your help.

Sincerely

  1. Add this to your 2nd question text richcontent editor → source
    div id="messageDisplay"></div>

     

  2. Add this JS to the 2nd question
    Qualtrics.SurveyEngine.addOnload(function() {
    var npsScore = parseInt("${q://QID1/ChoiceGroup/SelectedChoices}");
    var message = "";

    if (npsScore >= 0 && npsScore <= 6) {
    message = "Sorry";
    } else if (npsScore >= 7 && npsScore <= 8) {
    message = "Good";
    } else if (npsScore >= 9 && npsScore <= 10) {
    message = "Very Good";
    }

    var messageElement = document.getElementById("messageDisplay");
    if (messageElement) {
    messageElement.innerHTML = message;
    }
    });

    Note: I’m assuming Id of Q1 is QID1 so please check if ${q://QID1/ChoiceGroup/SelectedChoices} pull out the correct Q1 value and change it if necessary.

Hope this helps

5 replies

Forum|alt.badge.img+14
  • Level 5 ●●●●●
  • 276 replies
  • October 16, 2023

You could create three different questions with display logic for each where if 0-6 is selected, it displays “sorry,” if 7-8 is selected, it displays “good.”


Forum|alt.badge.img+1
  • Author
  • 2 replies
  • October 16, 2023

Thank you for your response. Yes I know that but I wondered if I just could do with one question and add a condition with JavaScript.


Nam Nguyen
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+29
  • QPN Level 8 ●●●●●●●●
  • 1096 replies
  • Answer
  • October 17, 2023

Good morning,

I have a question in nps which goes from 0 to 10 in my question 1 "Q1". I created a second question without using display logic so that if I put in q1 between 0 to 6 it displays me in a paragraph "sorry", 7 to 8 "good" and 9 to 10 "very good " with js code but it's the first time I'm using it and I'm a little lost. Thank you very much for your help.

Sincerely

  1. Add this to your 2nd question text richcontent editor → source
    div id="messageDisplay"></div>

     

  2. Add this JS to the 2nd question
    Qualtrics.SurveyEngine.addOnload(function() {
    var npsScore = parseInt("${q://QID1/ChoiceGroup/SelectedChoices}");
    var message = "";

    if (npsScore >= 0 && npsScore <= 6) {
    message = "Sorry";
    } else if (npsScore >= 7 && npsScore <= 8) {
    message = "Good";
    } else if (npsScore >= 9 && npsScore <= 10) {
    message = "Very Good";
    }

    var messageElement = document.getElementById("messageDisplay");
    if (messageElement) {
    messageElement.innerHTML = message;
    }
    });

    Note: I’m assuming Id of Q1 is QID1 so please check if ${q://QID1/ChoiceGroup/SelectedChoices} pull out the correct Q1 value and change it if necessary.

Hope this helps


Forum|alt.badge.img+1
  • Author
  • 2 replies
  • October 17, 2023

Thank you so much, this really help me.


Nam Nguyen
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+29
  • QPN Level 8 ●●●●●●●●
  • 1096 replies
  • October 17, 2023

Thank you so much, this really help me.

Happy to help 👍