Custom Scripting? — how to test checkbox answers and carry those values into other questions?


I have the following:

QUESTION 1: Which vendors do you use?

Checkbox A Vendor

Checkbox B Vendor

Checkbox C Vendor

Checkbox D Vendor

To build the next question, I want to check to see which answers were chosen. IF CHECKBOX B Vendor is chosen, I always want to ask about that vendor and then randomly pick another vendor to be compared to B Vendor. If Vendor B is not chosen, then randomly pick two vendors.  Ideally I would have two mergecodes to carry through to the remaining questions that are the names of the two vendors.

So, if Vendor B was chosen, the next question would look like this (where Vendor D was chosen randomly from the checked vendors) —

Question 2: Compare these two vendors: Vendor B and Vendor D.

If Vendor B was NOT chosen, then the question would just pick two random chosen vendors.

Question 2: Compare these two vendors: Vendor C and Vendor A.

I would also need to check to make sure at least one vendor was chosen.


baahtweet answered

    Hi Baahtweet,

    This sounds very similar to the type of functionality I work with all the time.

    Now the first thing I would get out of the way is whether the questions need to be on the same page. The reason I ask that is you can achieve what you’re looking for in two different methods. If it is same page, you will need to utilize javascript. This means you will be getting the values via the DOM and it’s values. In comparison if you are OK with having the second question on a second page, you can utilize the merge codes. The reason I mention this is javascript can take place the second the user makes a selection, where as the SG Custom Scripting is PHP based that would take place before the page loads.

    When I do this, I utilize hidden questions and hidden values so that you can report out on things easy at a later time.

    I would create a hidden question that list out all 4 vendors with custom scripting to choose one of the options. For example, when the user selects Vendor A I would have custom scripting to notice that and randomly select one of the remaining vendors.

    In order to apply the custom logic of doing different actions based on the vendor that is selected, I would utilize IF statements. This can be done either way, javascript or Custom Scripting.

    I hope this is enough to get you started, if it is not, please let me know what you need to get moving forward.


    baahtweet commented
      • OK, I have created a hidden question that shows the results of the vendor choices (using the SurveyGizmo documentation, it is a textbox list where the label and the answer are the names of the vendors). What is an example of an IF statement that will work on the results? For example, I am able to get the string of vendors using this: [question(“option value”), id=”263″, finaldelimiter=” and “]. I can get the individual answers using this:[question(“option value”), id=”263″, option=”10363″], [question(“option value”), id=”263″, option=”10364″], etc.

        I would like to create two custom variables, vendor1 and vendor2, or some sort of mechanism where I can carry the names of the vendors throughout the rest of the survey. Can you give an example on how to create the IF statements to create these two variables?




      Question stats

      • Active
      • Views15896 times
      • Answers1 answer
      • Followers1 follower