Have an idea?

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

How to get error message to display in grid question

I have a grid with 8 columns. I need an error message to display if a respondent marks a response for:
-column 4 but not column 3
-column 6 but not column 5
-column 8 but not column 7

Respondents are allowed to mark responses for column 1, column 3, column 5, and column 7.
If they mark a response for column 4 they must also respond to column 3.
If they mark column 6 they must also mark column 5 and 3
If they mark column 8 they must also mark column 7, 5, and 3
asked May 11, 2018 by kaitlan (200 points)
What type of grid question?
It is a select grid question with check boxes for multiple responses

1 Answer

+1 vote
 
Best answer
Custom verification:

var checks = [];
var rows = $('input[name="hid_row_list_[% QuestionName() %]"]').val().split(',');
var cols = $('input[name="hid_col_list_[% QuestionName() %]"]').val().split(',');
cols.forEach(function(col){
    var colChecks = 0;
    rows.forEach(function(row){
        if (SSI_GetValue('[% QuestionName() %]_r' + row + '_c' + col)) {
            colChecks++;
        }
    });
    checks[col] = colChecks;
});

if (checks[4] > 0 && checks[3] == 0) {
    strErrorMessage = 'Error message';
}
if (checks[6] > 0 && checks[5] == 0) {
    strErrorMessage = 'Error message';
}
if (checks[8] > 0 && checks[7] == 0) {
    strErrorMessage = 'Error message';
}
answered May 11, 2018 by Zachary Platinum Sawtooth Software, Inc. (123,625 points)
selected May 11, 2018 by kaitlan
Thank you so much for your help!
...