Have an idea?

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

"Hide" a checkbox in a grid question - Part 2

This is a follow up to a question I asked a couple days ago...


Suppose I have this grid question - column based with checkboxes. (The "O"'s in my example are graphical checkboxes)

             A  B
Row 1  O  O
Row 2  O  O
Row 3  O  O

Now I have another gird question with the same format but I only want to display the checkboxes that were checked in the previous question.  In other words, if a respondent answers like this...

            A  B
Row 1  X  O
Row 2  X  O
Row 3  O  X

I want the next question to display this...

            A  B
Row 1  O
Row 2  O
Row 3       O

I can hide a checkbox in Q2 with the following code:

document.getElementById("Q2_r1_c1_graphical").visibility = 'hidden';
document.getElementById("Q2_r1_c1_graphical").disabled = 'true';
document.getElementById("Q2_r1_c1_graphical").className = 'HideElement';

But I can't figure out how to format the "if" part around it to base it on Q1.  Something like this...

if([%Q1_r1_c1%] <> 1)
document.getElementById("Q2_r1_c1_graphical").visibility = 'hidden';
document.getElementById("Q2_r1_c1_graphical").disabled = 'true';
document.getElementById("Q2_r1_c1_graphical").className = 'HideElement';
if([%Q1_r1_c2%] <> 1)
document.getElementById("Q2_r1_c2_graphical").visibility = 'hidden';
document.getElementById("Q2_r1_c2_graphical").disabled = 'true';
document.getElementById("Q2_r1_c2_graphical").className = 'HideElement';

...except that doesn't work.  The checkbox always displays no matter how I answer Q1.  I've tried it a hundred different ways but can't seems to get the syntax right - or maybe I'm missing something else.
asked Apr 18, 2012 by anonymous

2 Answers

+1 vote
instead of if([%Q1_r1_c1%] <> 1)
I believe you need to use if (SSI_GetValue ("Q1_r1_c1") <> 1)

The [%%] is used to just show the response, not actually pull the value of it up.
answered Apr 18, 2012 by Jay Rutherford Platinum (50,145 points)
actually no, as far as I remember the SSI_GetValue is to get answers from the current page, which haven't been written to the database, wheres the [%%] notation queries the database for earlier answers.
Thanks Jay, but that's one of the things I tried and no luck.  It seems I've tried every Combination of SSI_GetValue, VALUE, etc. and no matter what I do, the checkboxes always show.  The only way I can get them to not show is unconditionally.
Ah yes, my mistake.
+1 vote
if Q1 is a column based grid, its items will be named
Q1_c1_r1 instead of Q1_r1_c1 (notice the r vs c order)

if this is not the reason, then try
if([%Q1_r1_c1%] <> "1")

instead of
if([%Q1_r1_c1%] <> 1)

and let us know whether or not it worked
answered Apr 18, 2012 by Bahadir Ozkurt Gold (16,980 points)
Thanks Bahadir but I've tried your suggestions and no luck.  Q1 is a column based grid however when I export the data the variables names are "Q1_r1_c1" rather than "Q1_c1_r1".  When I use "Q1_c1_r1" in the code I get a 'symbol does not exist' error.

Putting quotes around the 1 did not do the trick either.
hmm, what do you get when you insert

before the ifs?
**HAPPY**  I've stumbled upon the solution.  Using
if([%Q1_r1_c1%] <> 1)

did not work.  In fact the alert statement (which I put before the 'if') did not even fire making me think that the whole script crashed.

However, using
if ([%Q1_r1_c1%] == 0)

did work!  Although I don't know why this way works and the other way doesn't.

Not to complicate this any more, but the rows in Q2 display conditionally based on whether there is a check under either column for that row in Q1.  My thinking in using "<> 1" is that it would handle cases where a row does not diaplay and the internal value would be "".  However it appears that the internal value is "0" even if the row doesn't display so the "==0" logic always works.

Thank you both for your help!!!
ah not equal operator is != in js :)