Add a script

Add a script to a question, content box, or entry quota.

Prerequisites:
  • You have a strong understanding of scripting in Community.
Note:
  • You can pipe variables into all script types.
  • CSS and JavaScript are not supported for mobile surveys.
  • Scripting is now available in surveys. For more information about how it works and what is possible, see Scripting in surveys.
  1. In the Question Editor, click Edit Scripts.
  2. Click the tab for the type of script that you are adding.
    Type Description
    On Load On Load scripts are used primarily for hiding question elements such as rows in a grid. The script runs before the question is displayed to a participant.
    On Validate

    On Validate scripts are used primarily to create custom messages in questions. For example, if participants enter a response in the wrong format, a message could appear that indicates the error and requires them to re-enter their response.

    This script runs when participants click Next. If there is no Next button, the script runs when participants enter an answer and the survey is about to move to the next question.

    On Exit On Exit scripts are used primarily to set hidden questions. The script runs after participants finish answering a question and move on to another question.
    JavaScript JavaScript is used to create custom behavior in the survey and to create processes that run behind the scenes. For example, you can write a script that enlarges images when participants click them.
    Style Style refers to Cascading Style Sheets (CSS) that can be added to the survey. Add CSS to create custom formatting for the questions.
  3. In the text box, type the script.
  4. Optional: Add a pipe to the script.
    1. Place the cursor where the pipe will be inserted.
    2. Click the Insert pipe button.
    3. From the list, select the pipe.
      • If pipe is added on the JavaScript or Style tab, the pipe value is added as a simple string value and appears in the following format: [%pipe%]
      • If the pipe is on the On Load, On Validate, or On Exit tab, the pipe is added as C# code.
  5. Click Save.
    Result: The script is saved on every Script Editor tab.
  6. To ensure that the script produces the expected results, test the script.
    Note: