Extrapolating a slider question into a list of all combinations | XM Community
Question

Extrapolating a slider question into a list of all combinations

  • 15 March 2024
  • 0 replies
  • 10 views

Badge +3

Hello,

 

I have a rather elaborate and specific issue that I am trying to resolve, and would appreciate any guidance that I can get on how I could implement this task (or if it’s even possible).

 

The situation is that I have a survey in which I want to ask respondents how many of a range of products they have bought, then later ask them a series of questions on a limited number of those items.

For example,  I have a slider question, at which I ask people how many of each of 4 possible products they have bought. The scale goes from 0 to 10, so there could be a maximum of 40 total products bought.

Later in the survey, there will then be a looped block, where I want to ask about a maximum of 5 of the possible 40 products (to limit the length of the survey). i.e. the block will ask where they bough each item, how much it cost, etc.

In order to go from the item slider question to the block loop, I need to extrapolate out the slider into the total number of items they have bought…

e.g. say they had bought 10 of all 4 categories, then the list would be as follows:

  • 1. Category1 item 1
  • 2. Category2 item 1
  • 3. Category3 item 1
  • 4. Category4 item 1
  • 5. Category1 item 2
  • 6. Category2 item 2
  • 7. Category3 item 2
  • 39. Category4 item 9
  • 40. Category4 item 10

...and then I limit that list to the first 5, so that I can use that list to pipe into the ‘Loop & Merge’ setting.

e.g. In this example, I want to ask about the 1st item of each of the 4 categories & one of the 2nd items (to bring the total to 5 items in the block loop)

  • 1. Category1 item 1
  • 2. Category2 item 1
  • 3. Category3 item 1
  • 4. Category4 item 1
  • 5. Category1 item 2

 

I put this question to ChatGPT and it suggested making an interim MC question & using the following script to populate it (which would then feed into the block loop)…

Qualtrics.SurveyEngine.addOnload(function() {
var totalProducts = parseInt("${q://QID1/ChoiceNumericEntryValue/1}"); // Assuming QID1 is the ID of your slider question
var productList = [];

// Add options to the list based on the total products bought
for (var i = 1; i <= totalProducts; i++) {
productList.push({
value: 'Product ' + i,
text: 'Product ' + i
});
}

// Populate the "Product List" question with the generated options
var productListQuestion = this.questionId;
var select = $(productListQuestion).select('select');
productList.forEach(function(product) {
select.appendChild(new Option(product.text, product.value));
});

// Limit the maximum options displayed to 5
var maxOptions = 5;
if (select.options.length > maxOptions) {
while (select.options.length > maxOptions) {
select.remove(maxOptions);
}
}
});

This script, however, didn’t work during my test.

Is there anyone that could advise where I might be going wrong? If the above script should work, or an alternative method to achieve my goal?

 

Thanks in advance.


0 replies

Be the first to reply!

Leave a Reply