Skip to content

Instantly share code, notes, and snippets.

@marketinview
Last active October 23, 2022 16:56
Show Gist options
  • Save marketinview/5067945070f92101a0f4 to your computer and use it in GitHub Desktop.
Save marketinview/5067945070f92101a0f4 to your computer and use it in GitHub Desktop.
Qualtrics: Sum a Single Matrix Column. The last row in the Matrix question is a Total. In this example, the third input column (c6) is the one that is totaled and must add to 100. The totals for the first two input columns (c4 and c5) are hidden. The total is a readonly field so the respondent can't change it. The only other thing to do is add a…
Qualtrics.SurveyEngine.addOnload(function() {
var q = jQuery("#"+this.questionId);
q.find('td.c4:last input').hide();
q.find('td.c5:last input').hide();
var totalInput = q.find('td.c6:last input');
totalInput.prop("readonly", true);
totalInput.css("font-weight", "bold");
var sumInputs = q.find('td.c6:not(:last) input');
sumInputs.on("keyup", function(event) {
sumCol();
});
sumCol();
function sumCol() {
var total = 0;
sumInputs.each(function(index) {
var inputValue = parseInt(this.value);
if(isNaN(inputValue)) inputValue = 0;
this.value = inputValue;
total = total + inputValue;
});
totalInput.val(total);
if(total == 100) totalInput.css("color", "");
else totalInput.css("color", "red");
}
});
@marketinview
Copy link
Author

marketinview commented Nov 14, 2017

See additional Qualtrics solutions at: https://qualtricswiki.tgibbons.com/doku.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment