We’ve migrated our documentation to a new site, which means some URLs have changed. If you hit a broken link, submit a support ticket.
Subscriptions

How to add an averaging custom script to Survey Gizmo

Before adding custom scripting to your SurveyGizmo survey, complete this setup step so you can reference the correct question IDs later.

  1. In your survey, switch to Build mode.

  2. Open View Settings in the top-right corner, next to Restore.

  3. In the View Settings dropdown, select Question ID's. This adds a label to each question with its corresponding ID.

  4. For each question that provides values used in calculations, add a pseudo question. In most cases, these are the questions that ask for the four price inputs a user may pay.

  5. On the input question that will be used in the equation, add an additional question. Name it, set the format to Textbox, and open the Logic tab.

  6. Select Hide this question by default (mainly used with custom scripting).

  7. Record the IDs for the two values you want to average, as well as the ID of the pseudo question.

Next, add a custom script to the question where you want to display the average.

  1. Select Add New: Action, then choose Custom Script. Move the action above the averaged question if it is not already there.

  2. Add the following code to the 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
    
  3. Open Logic and give the custom script the same logic as the question it is tied to: the question that shows the average.

  4. In the question copy that needs to display the average, add [question('value'), id='z']. Replace z with the ID of the pseudo question.

Last updated: