Have an idea?

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

modify javascript to disable graphical inputs

I have this code, but would like to add to it so that if column 1 row 11 is selected,  nothing from column 2 can be selected

What do i add?

<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);
        }
    }
asked Mar 6 by anonymous
This is a column-oriented grid question, correct?

Do you want your requested behavior added to the code you have included, or do you want the original behavior to be replaced with this new behavior?
Yes, column oriented

And I want to add to this code, not replace it

1 Answer

0 votes
The fastest change would be to add another "else if" after the other one:

else if (c1Resp == 11) {
    c2Start = 1;
    c2End = 999;
}
answered Mar 6 by Zachary Platinum Sawtooth Software, Inc. (126,575 points)
so it looks like this now and doesn't work... did I add it in the wrong spot

<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;
    }
 
    else if (c1Resp == 11) {
           c2Start = 1;
        c2End = 999;
    }

    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);
        }
    }
I just deleted the blank row above it and now it choosing 11 only disables column 1-7 instead of 1-12
I noticed that the for loop at the end of the code expects there to be 7 rows.  If you have more than seven rows to disable in the second column, that number should be updated to reflect that.
It works, thanks!!
...