Have an idea?

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

Set hidden variable based on grid question

Hello, everyone,

I would like to set a dummy variable if someone gave the wrong answer in a grid question. For example, question 7 in a grid question says: "Please click on 7", but respondents click on 6.
Now I would like to set a hidden variable, whether respondents pay attention to the question or not. Furthermore, I would like to use a skip logic based on this dummy variable.

I created a hidden variable of the type "whole number" and try to use this script:

<input type="hidden" name="AttentionCheck1_Dummy" id="AttentionCheck1_Dummy" value="[% Begin Unverified Perl

if (GETVALUE('ItemsIdentity_r7') != 7)
    return 1;
    return 0;

End Unverified %]"/>

Unfortunately, the hidden variable is always set to 1, irrespective of the answer. What am I doing wrong?

Kind regards
closed with the note: It was just the order of the questions. Problem solved!
asked Sep 3, 2020 by Nico Bronze (800 points)
closed Sep 3, 2020 by Nico
Did you place the hidden question on a survey page after the grid question?

The Perl Script being on the same page will not work. JavaScript is the answer if you need the calculation made on the same page.

I suggest you place this free format question on a page after and then re-test. It can be placed on the same survey page as another existing question that appears after your grid question.
Thanks, this did the trick! :-)
Good work.

You can also use SetValue to store values in to a pass-in field. That way you don't even need a free format question.



You can also use this approach inside Perl Script.

Nice to have both options really.