Have an idea?

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

grid question error message?

I have a grid question (C10a) with two columns and 12 rows

The first column is required, the second column is optional

If respondents select 1,2,3, or 4 in the first column, i want to prohibit them from selecting row 5 in the second column

Similarly, if respondent selects 5,6 or 7 in first column, I want to prohibit them from selecting 1,2,3, or 4 in second column

Is there a way to do this
asked Dec 10, 2018 by anonymous
What input type is the grid using?  Radio buttons?
Yes, radio buttons

1 Answer

0 votes
Start by adding "Disable Graphical Inputs" from the Community Question Library into your questionnaire:

https://sawtoothsoftware.com/community-question-library/1739-disable-graphical-inputs

Then add this script to your grid question:

<script>
function SSI_CustomGraphicalRadiobox(graphicalObj, inputObj) {
    var c1Resp = SSI_GetValue('[% QuestionName() %]_c1');
    var c2Resp = SSI_GetValue('[% QuestionName() %]_c2');
    
    if (c1Resp >= 1 && c1Resp <= 4) {
        if (c2Resp == 5) {
            SSI_RadioReset('[% QuestionName() %]_c2');
        }
        SSI_DisableGraphicalInput('[% QuestionName() %]_c2_5');
    }
    else {
        SSI_EnableGraphicalInput('[% QuestionName() %]_c2_5');
    }
    
    if (c1Resp >= 5 && c1Resp <= 7) {
        if (c2Resp >= 1 && c2Resp <= 4) {
            SSI_RadioReset('[% QuestionName() %]_c2');
        }
        for (var i = 1; i <= 4; i++) {
            SSI_DisableGraphicalInput('[% QuestionName() %]_c2_' + i);
        }
    }
    else {
        for (var i = 1; i <= 4; i++) {
            SSI_EnableGraphicalInput('[% QuestionName() %]_c2_' + i);
        }
    }
}
</script>
answered Dec 10, 2018 by Zachary Platinum Sawtooth Software, Inc. (121,625 points)
Try this:

<script>
function SSI_CustomGraphicalRadiobox(graphicalObj, inputObj) {
    var c1Resp = SSI_GetValue('[% QuestionName() %]_c1');
    var c2Resp = SSI_GetValue('[% QuestionName() %]_c2');

    var c2Start = 0;
    var c2End = 0;

    if (c1Resp >= 1 && c1Resp <= 4) {
        c2Start = 5;
        c2End = 7;
    }
    else if (c1Resp >= 5 && c1Resp <= 7) {
        c2Start = 1;
        c2End = 4;
    }

    if (c2Resp >= c2Start && c2Resp <= c2End) {
        SSI_RadioReset('[% QuestionName() %]_c2');
    }

    for (var i = 1; i <= 7; i++) {
        if (i >= c2Start && i <= c2End) {
            SSI_DisableGraphicalInput('[% QuestionName() %]_c2_' + i);
        }
        else {
            SSI_EnableGraphicalInput('[% QuestionName() %]_c2_' + i);
        }
    }
}
</script>
When I add this code, nothing happens. Not sure why. Thanks for your help
What are you wanting the code to do for you?
This works! Is there a way to add to it so that row 8 cant be selected in column 1 and so that the response in column 1 cant be selected in column 2
To permanently disable that input, add this between lines 1 and 2 of my comment:

$(document).ready(function(){
    SSI_DisableGraphicalInput('[% QuestionName() %]_c2_8');
})


To prevent the same response in both columns, replace these lines:

if (c2Resp >= c2Start && c2Resp <= c2End) {

if (i >= c2Start && i <= c2End) {


with these lines, respectively:

if ((c2Resp >= c2Start && c2Resp <= c2End) || c2Resp == c1Resp) {

if ((i >= c2Start && i <= c2End) || i == c1Resp) {
...