Have an idea?

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

Grid Question Force Multiple Answers For a least one column

Hi there,

I am stuck on a checkbox grid multiple answers and I think I need a small java script code. My problem is as followed:

- I have a grid, checkboxes, answer direction is set on columns.
- Four columns (providers), four rows (products).

I want to force the respondent to choose AT LEAST two products (rows) from one provider (columns). For one provider at least, not all of them.  If he chooses three products (rows) but at three different providers (columns), it's wrong.
But I don't need two answers in every column, as I could easily do that in the settings of sawtooth.

And if he does not do that, display an error message when he clicks "next" like: "Please select at least two products from the same provider" to make sure he does.

Any help would be super helpful here!

asked Feb 12 by Antoine

1 Answer

0 votes
Does this custom JavaScript verification suit your needs?

var rows = $('input[name="hid_row_list_[% QuestionName() %]"]').val().split(',');
var columns = $('input[name="hid_col_list_[% QuestionName() %]"]').val().split(',');

var foundGoodColumn = false;
for (var c = 0; c < columns.length && !foundGoodColumn; c++) {
    var count = 0;
    for (var r = 0; r < rows.length && !foundGoodColumn; r++) {
        count += SSI_GetValue('[% QuestionName() %]_r' + rows[r] + '_c' + columns[c]);
        foundGoodColumn = count >= 2;

if (!foundGoodColumn) {
    strErrorMessage = 'Please select at least two...';
answered Feb 12 by Zachary Platinum Sawtooth Software, Inc. (144,125 points)
Thank you very much for this very quick answer!

Apologize to ask for more details but if the names of my questions are as followed:
Row = BundleProductChosen
Column = ChosenProvider
Q name = BundleProductProvider,

Would the top part of the code be like this:

var rows = $('input[name="BundleProductChosen_[% BundleProductProvider() %]"]').val().split(',');
var columns = $('input[name="ChosenProviders_[% BundleProductProvider() %]"]').val().split(',');

var foundGoodColumn = false;
for (var c = 0; c < columns.length && !foundGoodColumn; c++) {
        var count = 0;
        for (var r = 0; r < rows.length && !foundGoodColumn; r++) {
                count += SSI_GetValue('[% BundleProductProvider() %]_r' + rows[r] + '_c' + columns[c]);
                foundGoodColumn = count >= 2;

Sawtooth is displaying:

"Error: Question 'BundleProductProvider' - JavaScript - The function call 'BundleProductProvider' does not exist."  as an error when I do that,

Thanks again Zach much appreciated, I am not very familiar with Java, more Python
Besides changing the error message on line 14 to whatever you want it to say, nothing else in the script needs to be modified.