Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Javascript verification using listlength

Is there anyway to use the acutal listlength for a javascript verification?
asked Aug 9, 2018 by Stefan
Most Sawtooth Script functions, including ListLength, can be used in custom JavaScript verification.  Can you expound more on what verification you are trying to achieve?  Is there some ListLength code you have tried that isn't working?
thank you

i have two multi select qn and want to do a check (as it is standard for one single qn) that allows to tick from min to max amount of selections ober both qn on the same page.

i thought using listlength could help in any way here when AIC both qn is ised....
What minimum and maximum do you have in mind?  A simple constant like 4, or something more dynamic based off the items in the two questions?
Just static

1 Answer

0 votes
Try this custom JavaScript verification:

var questions = ['SelectQ1', 'SelectQ2'];
var minimumChecks = 2;
var maximumChecks = 4;
var minimumError = 'Too few.';
var maximumError = 'Too many.';

var checks = 0;
    var list = $('input[name=hid_list_' + question + ']').val().split(',');
    list.forEach(function(item) {
        checks += SSI_GetValue(question + '_' + item);
if (checks < minimumChecks) {
    strErrorMessage = minimumError;
else if (checks > maximumChecks) {
    strErrorMessage = maximumError;

Line 1 should be updated with the names of the select questions.  Lines 2 and 3 should be updated with the inclusive minimum and maximum, respectively.  Lines 4 and 5 can be updated with the messages to show respondents.
answered Aug 10, 2018 by Zachary Platinum Sawtooth Software, Inc. (114,175 points)