Have an idea?

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

Preselect script too long

Hi Guy,

I have select question (checkbox) more than 50 questions, when I want to use preselect script, I have to script like below.

Do you have any way to write script below in short?

<script type="text/javascript">
if("[% B14Ax19_11 %]"==1 || "[% B14Ax19_12 %]"==1 || "[% B14Ax19_13 %]"==1 || "[% B14Ax19_14 %]"==1 || "[% B14Ax19_15 %]"==1 || "[% B14Ax19_16 %]"==1 || "[% B14Ax19_17 %]"==1 || "[% B14Ax19_18 %]"==1 || "[% B14Ax19_19 %]"==1 || "[% B14Ax19_20 %]"==1 || "[% B14Ax19_21 %]"==1 || "[% B14Ax19_22 %]"==1 || "[% B14Ax20_20 %]"==1 || "[% B14Ax20_21 %]"==1 || "[% B14Ax20_22 %]"==1 || "[% B14Ax20_20 %]"==1 || "[% B14Ax20_21 %]"==1 || "[% B14Ax20_22 %]"==1 || "[% B14Ax20_20 %]"==1 || "[% B14Ax20_21 %]"==1 || "[% B14Ax20_22 %]"==1 || "[% B14Ax20_20 %]"==1 || "[% B14Ax20_21 %]"==1 || "[% B14Ax20_22 %]"==1 || "[% B14Ax21_20 %]"==1 || "[% B14Ax21_21 %]"==1 || "[% B14Ax21_22 %]"==1 || "[% B14Ax21_20 %]"==1 || "[% B14Ax21_21 %]"==1 || "[% B14Ax21_22 %]"==1 || "[% B14Ax21_20 %]"==1 || "[% B14Ax21_21 %]"==1 || "[% B14Ax21_22 %]"==1 || "[% B14Ax21_20 %]"==1 || "[% B14Ax21_21 %]"==1 || "[% B14Ax21_22 %]"==1 || "[% B14Ax22_20 %]"==1 || "[% B14Ax22_21 %]"==1 || "[% B14Ax22_22 %]"==1 || "[% B14Ax22_20 %]"==1 || "[% B14Ax22_21 %]"==1 || "[% B14Ax22_22 %]"==1 || "[% B14Ax22_20 %]"==1 || "[% B14Ax22_21 %]"==1 || "[% B14Ax22_22 %]"==1 || "[% B14Ax22_20 %]"==1 || "[% B14Ax22_21 %]"==1 || "[% B14Ax22_22 %]"==1 || "[% B14Ax23_20 %]"==1 || "[% B14Ax23_21 %]"==1 || "[% B14Ax23_22 %]"==1 || "[% B14Ax23_20 %]"==1 || "[% B14Ax23_21 %]"==1 || "[% B14Ax23_22 %]"==1 || "[% B14Ax23_20 %]"==1 || "[% B14Ax23_21 %]"==1 || "[% B14Ax23_22 %]"==1 || "[% B14Ax23_20 %]"==1 || "[% B14Ax23_21 %]"==1 || "[% B14Ax23_22 %]"==1 || "[% B14Ax24_20 %]"==1 || "[% B14Ax24_21 %]"==1 || "[% B14Ax24_22 %]"==1 || "[% B14Ax24_20 %]"==1 || "[% B14Ax24_21 %]"==1 || "[% B14Ax24_22 %]"==1 || "[% B14Ax24_20 %]"==1 || "[% B14Ax24_21 %]"==1 || "[% B14Ax24_22 %]"==1 || "[% B14Ax24_20 %]"==1 || "[% B14Ax24_21 %]"==1 || "[% B14Ax24_22 %]"==1 || "[% B14Ax25_20 %]"==1 || "[% B14Ax25_21 %]"==1 || "[% B14Ax25_22 %]"==1 || "[% B14Ax25_20 %]"==1 || "[% B14Ax25_21 %]"==1 || "[% B14Ax25_22 %]"==1 || "[% B14Ax25_20 %]"==1 || "[% B14Ax25_21 %]"==1 || "[% B14Ax25_22 %]"==1 || "[% B14Ax25_20 %]"==1 || "[% B14Ax25_21 %]"==1 || "[% B14Ax25_22 %]"==1 || "[% B14Ax26_20 %]"==1 || "[% B14Ax26_21 %]"==1 || "[% B14Ax26_22 %]"==1 || "[% B14Ax26_20 %]"==1 || "[% B14Ax26_21 %]"==1 || "[% B14Ax26_22 %]"==1 || "[% B14Ax26_20 %]"==1 || "[% B14Ax26_21 %]"==1 || "[% B14Ax26_22 %]"==1 || "[% B14Ax26_20 %]"==1 || "[% B14Ax26_21 %]"==1 || "[% B14Ax26_22 %]"==1 || "[% B14Ax27_20 %]"==1 || "[% B14Ax27_21 %]"==1 || "[% B14Ax27_22 %]"==1 || "[% B14Ax27_20 %]"==1 || "[% B14Ax27_21 %]"==1 || "[% B14Ax27_22 %]"==1 || "[% B14Ax27_20 %]"==1 || "[% B14Ax27_21 %]"==1 || "[% B14Ax27_22 %]"==1 || "[% B14Ax27_20 %]"==1 || "[% B14Ax27_21 %]"==1 || "[% B14Ax27_22 %]"==1 || "[% B14Ax28_20 %]"==1 || "[% B14Ax28_21 %]"==1 || "[% B14Ax28_22 %]"==1 || "[% B14Ax28_20 %]"==1 || "[% B14Ax28_21 %]"==1 || "[% B14Ax28_22 %]"==1 || "[% B14Ax28_20 %]"==1 || "[% B14Ax28_21 %]"==1 || "[% B14Ax28_22 %]"==1 || "[% B14Ax28_20 %]"==1 || "[% B14Ax28_21 %]"==1 || "[% B14Ax28_22 %]"==1 || "[% B14Ax29_20 %]"==1 || "[% B14Ax29_21 %]"==1 || "[% B14Ax29_22 %]"==1 || "[% B14Ax29_20 %]"==1 || "[% B14Ax29_21 %]"==1 || "[% B14Ax29_22 %]"==1 || "[% B14Ax29_20 %]"==1 || "[% B14Ax29_21 %]"==1 || "[% B14Ax29_22 %]"==1 || "[% B14Ax29_20 %]"==1 || "[% B14Ax29_21 %]"==1 || "[% B14Ax29_22 %]"==1 || "[% B14Ax30_20 %]"==1 || "[% B14Ax30_21 %]"==1 || "[% B14Ax30_22 %]"==1 || "[% B14Ax30_20 %]"==1 || "[% B14Ax30_21 %]"==1 || "[% B14Ax30_22 %]"==1 || "[% B14Ax30_20 %]"==1 || "[% B14Ax30_21 %]"==1 || "[% B14Ax30_22 %]"==1 || "[% B14Ax30_20 %]"==1 || "[% B14Ax30_21 %]"==1 || "[% B14Ax30_22 %]"==1 || "[% B14Ax31_20 %]"==1 || "[% B14Ax31_21 %]"==1 || "[% B14Ax31_22 %]"==1 || "[% B14Ax31_20 %]"==1 || "[% B14Ax31_21 %]"==1 || "[% B14Ax31_22 %]"==1 || "[% B14Ax31_20 %]"==1 || "[% B14Ax31_21 %]"==1 || "[% B14Ax31_22 %]"==1 || "[% B14Ax31_20 %]"==1 || "[% B14Ax31_21 %]"==1 || "[% B14Ax31_22 %]"==1 || "[% B14Ax32_20 %]"==1 || "[% B14Ax32_21 %]"==1 || "[% B14Ax32_22 %]"==1 || "[% B14Ax32_20 %]"==1 || "[% B14Ax32_21 %]"==1 || "[% B14Ax32_22 %]"==1 || "[% B14Ax32_20 %]"==1 || "[% B14Ax32_21 %]"==1 || "[% B14Ax32_22 %]"==1 || "[% B14Ax32_20 %]"==1 || "[% B14Ax32_21 %]"==1 || "[% B14Ax32_22 %]"==1 || "[% B14Ax33_20 %]"==1 || "[% B14Ax33_21 %]"==1 || "[% B14Ax33_22 %]"==1 || "[% B14Ax33_20 %]"==1 || "[% B14Ax33_21 %]"==1 || "[% B14Ax33_22 %]"==1 || "[% B14Ax33_20 %]"==1 || "[% B14Ax33_21 %]"==1 || "[% B14Ax33_22 %]"==1 || "[% B14Ax33_20 %]"==1 || "[% B14Ax33_21 %]"==1 || "[% B14Ax33_22 %]"==1 || "[% B14Ax34_20 %]"==1 || "[% B14Ax34_21 %]"==1 || "[% B14Ax34_22 %]"==1 || "[% B14Ax34_20 %]"==1 || "[% B14Ax34_21 %]"==1 || "[% B14Ax34_22 %]"==1 || "[% B14Ax34_20 %]"==1 || "[% B14Ax34_21 %]"==1 || "[% B14Ax34_22 %]"==1 || "[% B14Ax34_20 %]"==1 || "[% B14Ax34_21 %]"==1 || "[% B14Ax34_22 %]"==1 || "[% B14Ax35_20 %]"==1 || "[% B14Ax35_21 %]"==1 || "[% B14Ax35_22 %]"==1 || "[% B14Ax35_20 %]"==1 || "[% B14Ax35_21 %]"==1 || "[% B14Ax35_22 %]"==1 || "[% B14Ax35_20 %]"==1 || "[% B14Ax35_21 %]"==1 || "[% B14Ax35_22 %]"==1 || "[% B14Ax35_20 %]"==1 || "[% B14Ax35_21 %]"==1 || "[% B14Ax35_22 %]"==1 || "[% B14Ax36_20 %]"==1 || "[% B14Ax36_21 %]"==1 || "[% B14Ax36_22 %]"==1 || "[% B14Ax36_20 %]"==1 || "[% B14Ax36_21 %]"==1 || "[% B14Ax36_22 %]"==1 || "[% B14Ax36_20 %]"==1 || "[% B14Ax36_21 %]"==1 || "[% B14Ax36_22 %]"==1 || "[% B14Ax36_20 %]"==1 || "[% B14Ax36_21 %]"==1 || "[% B14Ax36_22 %]"==1)
{
SSI_SetSelect("DumB14ABC_4",true);
}
</script>


Is it possible? please
asked Aug 6 by Saroeun Bronze (2,715 points)
You definitely want to use loops when writing code like this.  You may have some copy-and-paste errors in your code so far, so I'm not certain what fields are meant to be checked with a loop.  Do you mean to check items 11 through 22 for all questions between B14Ax19 and B14Ax36?
Yes, that's right. I want to check items 11 through 22 for all questions from  B14Ax19 to B14Ax36. Can you fix it in detail?

1 Answer

0 votes
 
Best answer
Try this:

<script>
[% Begin Unverified Perl
for (my $question = 19; $question <= 36; $question++) {
    for (my $item = 11; $item <= 22; $item++) {
        if (GETVALUE('B14Ax' . $question . '_' . $item)) {
            return 'SSI_SetSelect("DumB14ABC_4", true);';
        }
    }
}
return '';
End Unverified %]
</script>
answered Aug 7 by Zachary Platinum Sawtooth Software, Inc. (184,925 points)
selected Aug 13 by Saroeun
Can I use this script to get pre-select from loop question?
The B14Ax question is being looped?
Yes, that's right.
Is DumB14ABC in the same loop?  So the pre-select for DumB14ABC is meant to be based off the B14Ax of the same loop iteration?
DumB14ABC is the new question not loop. But B14Ax is the loop question, if among of B14Ax have code 19 or 11 or 22 will DumB14ABC code 4 is True.
...