How to automatically submit a response based on a previous answer (NOT piped)


I have a series of questions that ask:
Q1 Which of these are appealing to you?
Then, based on those answers:
Q2 Which ONE of these is MOST appealing to you?

In one section of my survey, I have used piping for this, and in the case that a respondent only chooses only one answer in Q1, Q2 automatically submits this response as the ‘most appealing’, using this javascript:

var radio = $( “:radio” ).length;
if (radio == “1”) {
$(“:radio”).attr(‘checked’, ‘checked’);

However, in another section of my survey, I have used Answer Option logic instead of piping, as per this article: I needed to use the responses in further logic.

I need those questions to also automatically submit Q2 if only one option is chosen in Q1.

Jim W (Moderator) answered

    You can use the scripting function to perform this task.  Without actually writing the script, you would probably use the following functions:

    sgapiCheckboxTotalChecked to determine how many options have been checked (assuming it’s checkbox question).

    You would then need a IF/THEN statement to evaluate the value returned by this function.  

    More then one option selected >You should have Q2 hidden by default, and if more then one option has been selected, use the sgapiHideQuestion function to unhide Q2.

    Only one option selected > Keep Q2 hidden.  Use the sgapiGetValue to obtain the single answer from Q1. Use the sgapiSetValue to populate the response value for Q2.

    The documentation for these sgapi functions all have working examples that you can use to build your script.

    Good luck!

    Jim W (Moderator) edited answer


      Question stats

      • Active
      • Views3807 times
      • Answers1 answer
      • Followers1 follower