Have an idea?

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

Hide a checkbox from the previous question

Hi everyone,

I want to hide and uncheck boxes from the previous question.
These are 2 tables: Q1 and Q2 (the same lists)

4 rows, 8 columns.
If Q1_r1_c1 is not checked in Q1  =>  it must be hidden and disabled  in Q2 (Q2_r1_c1).

How to proceed please ?

Regards,
Sylvain
asked Mar 11 by Sylvain V

1 Answer

0 votes
You can use a constructed list at Q2 for your row list. This will only show the 4 rows that were checked at Q1 in column 1.

I am assuming Q1 and Q2 are on separate pages.

Pop this Perl Script in to your constructed list ...
Begin Unverified Perl

 my $i=1;

 for($i=1; $i<=4; $i++)
  {
   if (VALUE("Q1_r".$i."_c1")==1)
    {  
     ADD("RowList",$i);
    }  
  }

End Unverified

Change "RowList" to the name of the parent list you use at Q1 and Q2 as your row parent list.

If you would like to randomise the rows, simply add in a RANDOMIZE(); command above the "End Unverified" command.
answered Mar 11 by Paul Moon Platinum (89,980 points)
edited Mar 11 by Paul Moon
Thank you Paul for your quick response.
It doesn't seem to work.
I forgot an important detail: the table Q1 is multiple, several possible answers per column (1 to 4). The second table is only one possible answer per column. I can send you a slide to show you the desired result.

The button must remain present in Q2 if it was not checked in Q1 but disabled.

Thanks,
S
May I ask are these questions on separate pages? If they are on the same page, then a different JavaScript approach will be necessary.
Questions are on 2 different pages. Thanks Paul !
OK, thanks for confirming.

The Perl Script will hide the entire row at Q2 if the condition is not true. Is that what you are seeking? This Perl Script I provided should work if it is a simple matter of hiding the entire row at Q2. I just tested it out on an example.

Did you copy the Perl Script into the constructed row list for Q2 and update the parent list name?

And note that this Perl Script only looks at column 1 of Q1. Is that what you needed?

If you are still wanting to show the row at Q2 but disable the response options (the radio buttons), then JavaScript will be required instead.

The Perl Script would be the normal approach where it hides the entire row.
Hi Paul, Thank you for your feedback.
I confirm that we want to keep the line active and disable the response options (radio buttons in Q2)
OK, thanks.

Perl Script will not do exactly what you are seeking in this case. It would hide the entire row/s.

I'll point Zachary Anderson from Sawtooth Software to this post. He is a JavaScript wizard.

His JavaScript solution will display your rows but deactivate the rows based on the Q1 condition.

Stay tuned ...

Paul.
To disable graphical radio buttons or checkboxes, you'll want to start by including a copy of the Better Lighthouse Library on the same page as Q2.  You can download it from here:

https://sawtoothsoftware.com/resources/question-library/better-lighthouse-library

Then you can put this script into Q2 to get the behavior you're after:

<script>
$(document).ready(function(){
    var uncheckeds = [% Begin Unverified Perl
        # Params
        my $questionName = 'Q1';
        my $listName = 'list1';

        # Run
        my @uncheckeds = ();
        my $len = LISTLENGTH($listName);
        for (my $i = 1; $i <= $len; $i++) {
            if (!GETVALUE($questionName . '_r' . $i . '_c1')) {
                push(@uncheckeds, $i);
            }
        }
        return '[' . join(',', @uncheckeds) . ']';
    End Unverified %];
    
    uncheckeds.forEach(function(unchecked){
        SSI_DisableRadioButtonOrCheckbox('[% QuestionName() %]_r' + unchecked + '_c1');
    });
})
</script>


"Q1" and "list1" being the name of the first question and the name of the list of rows.
Thanks once again Zachary for chipping in. Great stuff mate.
...