piping limited number of options

0

Hello! 

I have a question A of type checkbox list. Respondent can choose any number of options. But  in the next question B of the form radiobutton grid I need show  in columns  only 6 answers  N answers given to question A.

This is done not to stretch radiobutton grid.

I found something similar to the code I need, but I do not know how to improve it for my specific needs

https://script.surveygizmo.com/help/piping-checkbox-to-grid

Thank you all for helping me  in advance

strasser90 answered
    2

    Hi Kirill,

    Here a solution which worked for me. Just copy the code below in a custom script and change the question ID’s. What you get as a result from the script: a radio button or checkbox question containing max. 6 randomly chosen options the respondent has given in the source question. Then you can use this resulting question as source for a piping in the columns of your radio grid.

    Good luck

    Jan

    //Source: a multiple choice checkbox question answered by the respondent. In this example with question ID 150
    //Target (result): a multiple choice question containing only a given maximum of the options which have been ticked by the respondent in source question. In this example with the question ID 152
    %%arr=sgapiGetValue(150);//get the answers of the question as an array
    sgapiShuffle(%%arr);//generate a random order of the answers
    %%toshow=6;//number of options to show in the subsequent question
    %%todelete=sgapiCount(%%arr)-%%toshow;//variable %%todelete=number of answers to delete
    for (%%i=0; %%i<%%todelete; %%i++)//loop: removing the last %%todelete answers in the array
    {
    %%scratch=sgapiArray_Pop(%%arr);//removes the last element in the array
    }
    sgapiSetValue(152,%%arr);//write the remaining answers as answer options in the subsequent questions

    Tatiana commented
      • Many thanks for your help! I’m infinitely glad that you decided to help me! Thank you very much again! I am immensely happy that I solved this problem!

      • Dear strasser90, I’m trying to use you script and it works perfectly, when respondent choose 6 and more options. but it doesn’t work when respondent choose lesse than 6 options. could you help me with this problem?

      ×

      Login

      Question stats

      • Active
      • Views1445 times
      • Answers1 answer
      • Followers1 follower