Calculate change percentage based on a number input from responses | XM Community
Question

Calculate change percentage based on a number input from responses

  • 6 January 2024
  • 1 reply
  • 44 views

Badge

I am working on a design for a question where a participant will type a number in the textbox. Then, a percentage number “(Input_number-210)/210” will appear below the text box. 

The following is the basic question:

The current price is $210.
What price do you want to offer?
(After you type the number, the change percentage will appear below. )

 

The following is theJavascript I tried. It shows nothing. Three things that I am not sure:

(1) Can we show the percentage after there is a number in the input box, within the same page, even the some block?

(2) There are a few function in the Javascript box. I am not sure which one to choose, or more than one needed?

(3) How to let the percentage number show right below the input box?

I would really appreciate your help! Thank you so much! 

Qualtrics.SurveyEngine.addOnload(function()

function calc(){ 
var disc = 0;
var cp =getVal(parseInt($jq('input[type="number"]').eq(0).val()));
if (cp>0)
{
change_p = Math.round(((cp - 210)/210)*100,2);
}
return change_p; };

});


1 reply

Userlevel 7
Badge +22

Hi @data_researcher_B You need to use on input method to call calc() function and then change the value of a tag value using JS.

Leave a Reply