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

0

*** URGENT HEP PLEASE ***

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];
sgapiSetValue(89,%%outb);

I also tried other variations like this …

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

or …

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

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

Thank you.

Kevin Lyons328882 answered
    0

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

    Kevin Lyons328882 answered
      ×

      Login

      Question stats

      • Active
      • Views257 times
      • Answers1 answer
      • Followers1 follower