Hi!
I am trying to create a variable that counts the number of choices that currently exist in my question to make a loop, as I need to browse the possible choices to evaluate if they have been checked and set them to a specific value. The options are dynamic, as they appear depending on whether a YES was given in two different previous questions. I think I could also get this value if I use the If else option, but I wanted to know if there is a possibility to do it with only one line of code and not 6 or 7. Here below is my code for more context of what I tried (numSelectableOptions):
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var x = jQuery("#" + this.questionId + " inpututype=text]").eq(0).val();
var y= jQuery("#" + this.questionId + " inpututype=text]").eq(1).val();
var z = jQuery("#" + this.questionId + " inpututype=text]").eq(2).val();
var numSelectableOptions = jQuery("#" + questionId + " .q-checkbox:not(.q-disabled)").length;
// Loop through each item and check if it's not empty (embedded variable has a value)
for (var i = 1; i <= numSelectableOptions; i++) {
var itemValue = Qualtrics.SurveyEngine.getEmbeddedData("Inha" + i); // Get the embedded variable value for each item
// If the itemValue is not empty (not equal to an empty string)
if (itemValue == "other specify (1):") {
Qualtrics.SurveyEngine.setEmbeddedData("Inha"+i, x);
}
if (itemValue == "other specify (2):") {
Qualtrics.SurveyEngine.setEmbeddedData("Inha"+i, y);
}
if (itemValue == "other specify (3):") {
Qualtrics.SurveyEngine.setEmbeddedData("Inha"+i, z);
}
}
});
And I also tried this:
var numChoices = jQuery('#' + questionId + ' .q-radio').length;
Nothing above works.
Thanks in advance for any suggestions.
Regards!