How to divide an answer and display the result ? | XM Community
Skip to main content
Solved

How to divide an answer and display the result ?

  • February 5, 2022
  • 2 replies
  • 51 views

Forum|alt.badge.img+1

Hi everyone,
I want to ask my respondents their annual salary and display right under their calculated Monthly salary (A mere /12 division). However, they should not be able to modify the Monthly salary.
I am obliged to do so, otherwise 20% of the respondants would enter their Monthly salary instead of the Annual one, and ruin the survey. By displaying their monthly salary they will correct their mistake.
Here an example of what I want to do :
image.pngThank you so much if you know how to help :)

Best answer by TomG

You can use JavaScript like this:
Qualtrics.SurveyEngine.addOnload(function() {
var input =  jQuery("#"+this.questionId+" .InputText")
.after("

Monthly salary:
");
var monthly = jQuery("#"+this.questionId+" .monthly");
input.on("input", function() {
if(isNaN(this.value)) monthly.text("");
else monthly.text((this.value/12).toFixed(0));
});
});

2 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Answer
  • February 5, 2022

You can use JavaScript like this:
Qualtrics.SurveyEngine.addOnload(function() {
var input =  jQuery("#"+this.questionId+" .InputText")
.after("

Monthly salary:
");
var monthly = jQuery("#"+this.questionId+" .monthly");
input.on("input", function() {
if(isNaN(this.value)) monthly.text("");
else monthly.text((this.value/12).toFixed(0));
});
});


Forum|alt.badge.img+1
  • Author
  • February 6, 2022

TomG thank you so much !!! It works ! Than you so much you are the best.