Hello! I am trying to do something that seems a bit complicated.
Basically have a matrix table question and I'm trying to insert a column which automatically calculates and displays a number, based on the values inserted in other columns. Just as an example, column 5 would display the math operation (column 3/column 4).
Could someone help me do the coding for this, especially when I need the table to be formatted according to carry forwarded items on the left hand side of the table?
Thanks!
Page 1 / 1
Hi
Assuming that you are keeping the structure as above adn there no other questions present on the page, you can achieve the above functionality, by using below code:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
});
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
function calc() {
const box_1 = document.querySelectorAll('inputuid*="~3"]"type="text"]');
const box_2 = document.querySelectorAll('inputuid*="~4"]"type="text"]');
const mos = document.querySelectorAll('inputuid*="~5"]"type="text"]');
for (let i = 0; i < mos.length; i++) {
mosoi].disabled=true;
const value1 = parseInt(box_1_i].value);
const value2 = parseInt(box_2_i].value);
if (isNaN(value1) || isNaN(value2)) {
mosoi].value = 0;
} else {
mosoi].value = value1 / value2;
}
}
}
document.getElementById("Questions").addEventListener("input", calc);
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
});
Hope this resolves your query!!
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.