Troubleshooting - dynamically display calculated value | XM Community
Skip to main content

Hello! I have gotten a very basic understanding of some JQuery and HTML from previous posts and w3schools. I’m sure it’s something horribly obvious, but I can’t figure out what I’m doing wrong when I try to duplicate the code from this post: Display math operation results real-time | XM Community (qualtrics.com)

I have a form field question with three fields. In the question text, I put <div id = “total”></div>, and I have this code:

Qualtrics.SurveyEngine.addOnReady(function()
{
var textInputs = jQuery("#"+this.questionId+" .InputText");
    textInputs.blur(function() {
var txtFirstNumberValue = parseInt(textInputs.eq(0).val());
var txtSecondNumberValue = parseInt(textInputs.eq(1).val());
var txtThirdNumberValue = parseInt(textInputs.eq(2).val());
var result =parseInt(txtFirstNumberValue)*2 + parseInt(txtSecondNumberValue)*3+ parseInt(txtThirdNumberValue)*5;
jQuery("#total").text(result);

});
});

 

But nothing shows up for the total when I enter values into the question’s text boxes. Am I defining the HTML element incorrectly?

 

You html and code look OK, other than it will display NaN until you fill in all the amounts.  Are you using simple layout? If so, that’s your problem.


@TomG THANK YOU for saving me from my idiotic ignorance!


Leave a Reply