Randomly select a code from a check box question and save in a hidden question



I have a question Q4a. This is a check box question.

I would like to randomly select ONE response only from the responses selected by the respondent and save it in a hidden question. I need this for displaying in later questions.

I have had some success with saving a defined code to the hidden question using custom script.

e.g. sgapiSetValue(89,5);

My hidden question has questionID of “89”. In the above example I am saving a “5” to my hidden question. That works fine.

When attempting to save a randomly selected code from the responses chosen by the respondent, I encounter problems.

I tried this custom script where I use sgapiArray_Rand to extract ONE random response from Q4a and then used sgapiSetValue to set the hidden question. It appears I am having issues accessing the array correctly?

%%q4a_id = sgapiGetValue(23);

%%outa = sgapiArray_Rand(%%q4a_id,1);
%%outb = %%outa[0];

I also tried other variations like this …

%%outa = sgapiArray_Rand(%%q4a_id,1);

or …

%%outa = sgapiArray_Rand(%%q4a_id,1);

If someone could provide the correct script, that would be greatly appreciated.

Thank you.

Kevin Lyons328882 answered

    I need to do something similar to this. Did you ever figure out how to accomplish this? Thanks!

    Kevin Lyons328882 answered


      Question stats

      • Active
      • Views4736 times
      • Answers1 answer
      • Followers1 follower