@O.kisa,
Please post your JS code.
@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);
}
});
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;