I need mathematical operation to be performed in page as follows. The entry in the 2nd row needs to be multiplied by entry in 1st row and the result to be ideally displayed in the second row. Similarly, for 2nd and 3rd row as written in the table.
a. Enter number of members | >Numerical entry] | >Numerical entry] |
b. Proportion of members Eligible | ____% >Numerical entry] >Display actual number of members by multiplying entry in a by entry in b] | ____% >Numerical entry] >Display actual number of members by multiplying entry in a by entry in b] |
c. Proportion of Eligible members that are accepter | ____% >Numerical entry] >Display actual number of members by multiplying calculated number in b by entry in c] | ____% >Numerical entry] >Display actual number of members by multiplying calculated number in b by entry in c] |
I would really appreciate some help with custom code on this.
I do have another code that I wrote for a similar function where a text entry input was multiplied by a fixed number and displayed below the text box.
I’m only unable to make it work for matrix text boxes and with piped text from the same page.
Here’s the code that I have
Qualtrics.SurveyEngine.addOnReady(function() {
var qid = this.questionId;
var $inputBox =
jQuery("#" + qid + " .InputText");
// Create an element to display
the result
var $resultDisplay =
jQuery("<div id='resultDisplay' style='margin-top: 10px; font-size:
16px;'></div>");
$inputBox.after($resultDisplay);
// Function to calculate and
display the result
function
calculateAndDisplayResult() {
var inputValue =
parseFloat($inputBox.val());
if (!isNaN(inputValue)) {
var result = inputValue *
3320000;
$resultDisplay.text("Result: " +
result.toLocaleString());
} else {
$resultDisplay.text("");
}
}
// Trigger calculation when the
input changes
$inputBox.on("input", calculateAndDisplayResult);
});