We’ve migrated our documentation to a new site, which means some URLs have changed.
Subscriptions

How to add an averaging custom script to Survey Gizmo

In order to add custom scripting to your SurveyGizmo survey, there is one important setup requirement.

  1. While in "build" mode on your survey, navigate to "View Settings" in the top right next to "Restore". While in "View Settings" dropdown, check the box for "Question ID's". This applies a label to each question with its corresponding ID. The ID(s) are important later when writing a custom script. For each question that populates values to be included in equations, later on, you will want to add a pseudo question. (In most common cases, these are the questions that ask 4 inputs about what prices the user may pay).

  2. Once on the question asking for the inputs that will later be part of the equation, add an additional question. Edit that question, name it, select Textbox as the format, and navigate to the "Logic" tab. Check the box for "Hide this question by default (mainly used with custom scripting)".

  3. Notate the ID of the two values you want to average and the ID of the pseudo question.

Finally, you'll want to add a custom script to the question you are hoping to populate the average on.

  1. Click "Add New: Action" and select Custom Script (move to be above your averaged question if it isn't already).
    Add the following code to your custom script

    value1 = getvalue(x) --x should equal the ID of the first value value2 = getvalue(y) --y should equal the ID of the second value average = ((value1 + value2)/2) --Average of the values

    setvalue(z,average) --Sets hidden value --z should equal the ID of the pseudo question

  2. Click "Logic" and give your custom script the same logic as the question it is tied to (the one that shows the average).

  3. In the question copy that needs to populate the average, add [question('value'), id='z'] to pull in the value we set as average in the custom script where z equals the ID of the pseudo question.

Last updated: