Before adding custom scripting to your SurveyGizmo survey, complete this setup step so you can reference the correct question IDs later.
-
In your survey, switch to Build mode.
-
Open View Settings in the top-right corner, next to Restore.
-
In the View Settings dropdown, select Question ID's. This adds a label to each question with its corresponding ID.
-
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.
-
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.
-
Select Hide this question by default (mainly used with custom scripting).
-
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.
-
Select Add New: Action, then choose Custom Script. Move the action above the averaged question if it is not already there.
-
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 -
Open Logic and give the custom script the same logic as the question it is tied to: the question that shows the average.
-
In the question copy that needs to display the average, add
[question('value'), id='z']. Replacezwith the ID of the pseudo question.