Highlighter question logic check | XM Community
Skip to main content

Sorry, new to Javascript in Qualtrics.

I have a highlighter question that makes participants choose 5 consecutive numbers from 0 - 24. 

How do I extract the numbers selected from the highlighter question and ensure that they are a consecutive array (i.e., 2, 3, 4, 5, 6)?  

Would it also be possible to add this as a custom validation? 

 

Since the selections need to be consecutive in order to pass the validation, I think you can put this in place just by using Custom Validation and a lot of clicking. You could set 21 Logic Sets where each checks for a selected count of 5 and that the 5 selections are consecutive numbers. It could like something like the below, with 19 more sets for each potential combination of 5 consecutive numbers (20 being the highest selection for the first number to have the fifth selection be 24). 

To get the selection data in the format you’re looking for, you could use Branching and setting Embedded Data in the Survey Flow with the same Logic as above. Something like the below:

 


If you are up for writing some JS, a more flexible approach would be to use getSelectedChoices() and getSelectedAnswerValue() in addOnPageSubmit() to determine if  the answers are consecutive. Use that result to answer a hidden question on the page, and use that question in a validation condition of your highlight question.


Thanks a lot Tom_1842 & TomG for your help!

I was previously trying 

this.validateSelectedResponses = function() {
        var selectedResponses = this.getSelectedResponseValues();
        var selectedNumbers = selectedResponses.map(function(response) {
            return parseInt(response, 5)}

in the add on load section. Am still trying to build the other sections in the meantime, not sure if this is the right step forward?


Leave a Reply