I have a multiple choice question that is simply this:
Which of the following years did you participate (select all that apply)? 2019 2020 2021 2022 2023
A later question asks:
Relative to ${e://Field/largestYear}, how would you rate the following?
So clearly, I want only the highest selected year in the prior question to be piped into the second question as largestYear.
This is the jscript attached to the first question:
Qualtrics.SurveyEngine.addOnload(function() {
// Wait until the respondent has interacted with the question
this.questionclick = function(event, element) {
// Initialize max value
var max = 2019;
// Loop through selected choices
jQuery("#"+this.questionId+" .ChoiceStructure tbody tr").each(function() {
// Check if choice is selected
if (jQuery(this).find(".Selected").length > 0) {
// Retrieve numerical value of choice
var value = parseFloat(jQuery(this).find("td:first").text());
// Update max value if necessary
if (value > max) {
max = value;
}
}
});
// Set the embedded data with the largest value
Qualtrics.SurveyEngine.setEmbeddedData('largestYear', max);
}
});
The resulting imbedded data in question two always turns out to be equal to the assignment in the jscript line var max = 2019
no matter what (numeric) value I put into that statement. I have no experience coding java and have no experiencing debugging under Qualtrics, but I assume the line var value = parseFloat(jQuery(this).find("td:first").text())
is the problem. So I tried to recode the responses, so that it is a numbered list from 1 to 5, and that did not work, and I tried variable naming - figured, what the heck? It can't hurt at this point.
I'm hoping someone here has some thoughts on what I'm doing wrong. I tried asking this on Qualtrics Community, but it seems to have locked me out for too many log in attempts.
Any thoughts will be appreciated. Steve
I eventually got this question posted on the Qualtrics user group, where a poster suggested the following code that was able to accomplish this task based on the ordering of the choices - from earlier to later years:
Qualtrics.SurveyEngine.addOnload(function() {
this.questionclick = function(event, element) {
Qualtrics.SurveyEngine.setEmbeddedData('RecentYear', this.getQuestionInfo().Choices[this.getSelectedChoices().last()].Text);
}
});