Community Groups are officially here!
We've released Groups, a new feature that enables us to connect community members of similar industries and interests in a shared, private space. You can check out all of the details here, including information about who can join, how to join, and what Groups are currently offered. Please leave your feedback through this Community Groups Feedback Survey.

Math Results not showing up

Lokendra
Lokendra AustraliaCommunity Member Qubie ✭
edited August 2 in Custom Code

Hi,

I'm trying to do a math operation where the survey respondent starts with $x. A choice that the survey respondent makes should deduct $y from this initial amount (for simplicity, let x and y be 1). I am trying to show the remaining amount dynamically using Qualtrics Math operations or Javascript. However, during testing, the results of the math operations are showing up as blank.

How can I fix this? Would really appreciate all the help, thanks!


This is my code in Javascript:


This is the logic I'm using in the question text for the math operation to display:

This is the blank result I get during testing:


Best Answer

  • Lokendra
    Lokendra AustraliaCommunity Member Qubie ✭
    Accepted Answer

    Thanks to everyone who left a comment here to help!

    I believe the issue was with me re-using embedded data objects based on if statements. I re-did the survey again using a separate embedded data object for each individual calculation and it worked.

Answers

  • cbhavsar
    cbhavsar Mumbai, IndiaCommunity Member, Qualtrics Brand Admin Guru ✭✭

    Hi Lokendra,

    In this case, Javascript triggers after page load henceforth it will not dynamically updated on the same page, however if you refer the variable on the next page - you will be able to see the calculation result.

    In your case you can achieve this without using JavaScript paste below code in the question text:

    $e{e://Field/P2endowment + e://Field/DecisionCost}

    If this works for you, please accept this as an answer.

    All the best for your project!

  • Lokendra
    Lokendra AustraliaCommunity Member Qubie ✭

    Hi Cbhavsar,

    Thanks for the tip, but I've already tried using in-built Qualtrics math operations. The same problem as above occurred. Any instance where I used math to get a result dynamically showed up as blank during testing.



  • ahmedA
    ahmedA IndiaCommunity Member, XMPN Member Wizard ✭✭✭✭✭

    Qualtrics returns all values as stings and JS doesn't know how to perform subtraction on strings. Check your console you'll be getting some errors related to it.

    Wrap your values so that JS knows they are numbers like this: Number(Qualtrics.SurveyEngine.getEmbeddedData(...,... ))

  • cbhavsar
    cbhavsar Mumbai, IndiaCommunity Member, Qualtrics Brand Admin Guru ✭✭

    Hi, I am not sure why in your embedded shows 'Number Set' field. I tried the below code, it is working fine. Can you try with this and then procced further: