Add and Subtraction | Experience Community
Skip to main content
Solved

Add and Subtraction

  • Jan 19, 2025 6:41 PM UTC
  • 4 replies
  • 132 views

Forum|alt.badge.img+3

Hello everyone, I want to add two embedded data. One of the embedded data is a fixed number and the other is the addition of the income from the tasks. I can see the mathematical addition result in the console, but not on the qualtrics page. I did not understand why it’s happening. Could someone please help me with that?

Thank you in advance.

Best.

Best answer by TomG

You could do this without JavaScript. In survey flow:

Embedded Data:
   totalIncome = $e{ e://Field/guaranteedPayment + e://Field/totalECU }

You can pipe either ${e://Field/totalIncome} OR $e{ e://Field/guaranteedPayment + e://Field/totalECU } into a question (depending on if you do the survey flow calculation before or after the survey block)

If you want to calculate something in JavaScript and display it immediately in html, you need to update an element’s innerHTML. For example, if you had an html like this:

<div id="totalIncome"></div>

You could update it like this:

document.getElementById("totalIncome").innerHTML = totalIncome;

 

View original

4 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Jan 20, 2025 3:14 PM UTC

​@O.kisa,

Please post your JS code.


Forum|alt.badge.img+3
  • Author
  • Level 2 ●●
  • Jan 20, 2025 5:38 PM UTC

​@O.kisa,

Please post your JS code.

Thank you. Here it is:

Qualtrics.SurveyEngine.addOnload(function() {

    var guaranteedPayment = parseInt("${e://Field/Guaranteed_Payment}");

    var totalECU = parseInt("${e://Field/Total_ECU}");

   

    console.log("Guaranteed_Payment:", guaranteedPayment);

    console.log("Total_ECU:", totalECU);

   

    if (isNaN(guaranteedPayment) || isNaN(totalECU)) {

        console.error("Error: Embedded data values are not valid numbers.");

    } else {

        var totalIncome = guaranteedPayment + totalECU;

       

        Qualtrics.SurveyEngine.setEmbeddedData("Total_Income", totalIncome);

        console.log("Total Income saved:", totalIncome);

    }

});


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Answer
  • Jan 20, 2025 6:14 PM UTC

You could do this without JavaScript. In survey flow:

Embedded Data:
   totalIncome = $e{ e://Field/guaranteedPayment + e://Field/totalECU }

You can pipe either ${e://Field/totalIncome} OR $e{ e://Field/guaranteedPayment + e://Field/totalECU } into a question (depending on if you do the survey flow calculation before or after the survey block)

If you want to calculate something in JavaScript and display it immediately in html, you need to update an element’s innerHTML. For example, if you had an html like this:

<div id="totalIncome"></div>

You could update it like this:

document.getElementById("totalIncome").innerHTML = totalIncome;

 


Forum|alt.badge.img+3
  • Author
  • Level 2 ●●
  • Jan 21, 2025 10:36 AM UTC

 

You could do this without JavaScript. In survey flow:

Embedded Data:
   totalIncome = $e{ e://Field/guaranteedPayment + e://Field/totalECU }

You can pipe either ${e://Field/totalIncome} OR $e{ e://Field/guaranteedPayment + e://Field/totalECU } into a question (depending on if you do the survey flow calculation before or after the survey block)

If you want to calculate something in JavaScript and display it immediately in html, you need to update an element’s innerHTML. For example, if you had an html like this:

<div id="totalIncome"></div>

You could update it like this:

document.getElementById("totalIncome").innerHTML = totalIncome;

 

Thank you. Solved it.