I am completely new to Qualtrics and I have no experience with HTML or JavaScript, so I am hoping someone in the Qualtrics Community can help me.
I have set up a matrix question that asks survey respondents how much time their business spent on seven different tax compliance activities, by asking them to input numbers into side-by-side text boxes - see image below. I need to calculate the total amount of time spent on all activities, and then pipe that total (expressed in hours and minutes) into the subsequent question. The total box options in the matrix question don't work here, as they do a simple total of the numbers in each text box. I need the overall total to be expressed in hours and minutes, eg. 2 hours and 43 minutes, and NOT 1 hour and 103 minutes. Any assistance would be much appreciated - cheers!
Totalling hours and minutes from a matrix question
Best answer by ahmedA
Try this JS:
Qualtrics.SurveyEngine.addOnReady(function () {
let quest = this;
let all_inputs = Array.from(quest.questionContainer.querySelectorAll("input[id^=QR\\\\~]"));
let hrs = [],
mns = [];
all_inputs.forEach((item) => {
if (item.id.split("~")[3] == 1) {
hrs.push(item);
} else if (item.id.split("~")[3] == 2) {
mns.push(item);
}
});
document.querySelector("#NextButton").onclick = function () {
let tot_time = 0;
hrs.forEach((item, index) => {
tot_time += 60 * Number(item.value);
tot_time += Number(mns[index].value);
});
let mins = tot_time % 60;
let hours = (tot_time - mins) / 60;
let time_spent = hours + " Hours and " + mins + " Minutes";
Qualtrics.SurveyEngine.setEmbeddedData("time_spent", time_spent);
};
});
You'll get an embedded variable called
time_spent, which you can pipe to other questions.
Sign up
Already have an account? Login
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login to the Community
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
