Custom JavaScript validation - How to? [Deprecated]

When should I consider using JavaScript validation on the question?

There are multiple scenarios where JavaScript validation could be extremely handy and useful to solve your complex validation problems. For instance :

  • You want to validate complex questions like flex matrix, conjoint, heatmap etc, where system validations would be limited.
  • Where you would want to validate the question based on response to prior questions in the survey.
  • Do client side validation so the request is not submitted to the server.
  • Very specific/ custom validation on any question type. For instance you want only people who select 1 option from first 5 choices and 1 option from second 5 choices to multiple choice question to proceed.

What are the possible validations I can achieve with this feature

If you are a average to good JavaScript programmer you can solve any validation problem with this feature. A novice to JS could learn the basics and should be able to use the feature to solve straight forward validation problems in the survey.

How do I set up the custom JS validation? Any Example I can see?

Here is a use case that explains how to set up a simple JS validation script on the question. Lets assume that in the below mentioned survey we dont want people who have selected Monthly for Q1 which is on Page 1 of the survey and Visa for Q2 which on Page 2 to proceed.

  • Step 1 :We will need to set the JS validation script on question Q2 (Credit Cards) to solve this problem.

  • Go to: Login » Surveys » Workspace » Logic » JavaScript Logic

  • Enable the option for Pre JavaScript Validation to write the JS code.

    Survey Software Help Image
  • This is what the respondent will see if he selects Monthly for Q1 and Visa for Q2

    Survey Software Help Image

I am trying to validate a question that is on the 5th page of the survey, Can I refer to the question that is on the first page as its shown in the example

Yes. You can refer to all the questions that are loaded prior to the question that you are setting the validation on. The values are carried through to the finish page of the survey.

When writing a custom JavaScript on the question can I refer to previous question responses that are not on the same page ?

Yes. You can refer to prior responses in the survey. All the responses are stored in JavaScript Variables and restored all the way through the survey.

How can I refer to use the response to prior questions in the survey ?

You can refer the responses to following question types. Where number in the top right corner would be the question code for that question

Multiple Choice Many Select

Survey Software Help Image

Drop Down Menu

Survey Software Help Image

Comment / Suggestion Box

Survey Software Help Image

Single Row Text

Survey Software Help Image

Numeric (freeform) Input

Survey Software Help Image

Email Address

Survey Software Help Image

Multi-Point Scales

Survey Software Help Image

Checkbox / MultiSelect

Survey Software Help Image


Survey Software Help Image

Scale (Graphical)

Survey Software Help Image

Rank Order

Survey Software Help Image

Side-By-Side Matrix

Survey Software Help Image

Dynamic Lookup Table

Survey Software Help Image

Net Promoter Score

Survey Software Help Image


This feature is available with the following licenses:

Team and Enterprise

Was this article helpful?
Sorry about that
How can we improve it?