JavaScript is a powerful and widely-adopted programming language that excels in client-side scripting within web browsers. It allows developers to create dynamic and interactive web applications. In Zoho Survey, you can leverage JavaScript for implementing conditions and piping within various modules, enhancing the customization and functionality of your surveys. This capability enables you to tailor the user experience based on responses, making your surveys more engaging and effective.
To add a custom script in question:
Go to Builder>Editor and add the question type you'd like to use on the Survey Builder page using drag and drop or clicking on it in the left pane.
Click on the Insert Variable dropdown in the top-right corner and choose JavaScript Snippet.
Enter the code. Click insert variable(inside one) to use built-in functions in your code.
Click Test with sample data.
Click the Run button and check your result.
Click the Save button.
To add a custom script for answer display logic:
Go to Builder>Editor and add the question type you'd like to use on the Survey Builder page by drag and drop or clicking on it in the left pane.
Navigate to Answer Display Logic and click Add Logic.
Click If and select the JavaScript snippet.
Add the custom script required to run the required logic. You can also test run the code to ensure the logic works.
Click UPDATE and SAVE the code.
How to add a JavaScript for Page Skip logic :
To add a custom script for Page Skip Logic:
Go to Builder>Editor and click the Logic icon at the top-right corner of the page. Select Page Skip Logic.
In the new window, click Add Condition. Click If and select JavaScript Snippet.
Add the required custom script. You can also test run the code to ensure the logic works.
In the Default Flow, select the page to skip when the custom script logic works.
How to add a JavaScript for Trigger Email:
To add a custom script for Trigger Email:
Go to Builder>Hub>Triggers and click the CREATE Trigger Emails.
Click the ADD CONDITON button at the top-right corner.
Click If and select JavaScript Snippet.
Add the required custom script. You can also test run the code to ensure the logic works.
Add your sender email address andany other necessary fields to the email settings for sending the email when the custom script condition returns True.
How to add a JavaScript for the Survey End Page logic:
To add a custom script for Survey End page logic:
Go to Builder>Settings>Survey End page and click Add Logic.
Click If and select Javascript snippet from the dropdown.
Add the required custom script. You can also test run the code to ensure the logic works.
In the Default Flow, select the page to skip when the custom script logic works.
Click SAVE at the bottom of the page to confirm the changes.
JavaScript can be used for piping in 2 places, namely in the Custom message and in Re-direct to a new page when it comes to the Survey End Page customization.
To add a custom script for a custom message in the Survey End page:
Go to Builder>Settings>Survey End Page and click Add Logic.
Click If, scroll down, and select Javascript Snippet.
Add the custom script required for piping and test run the code to ensure it works.
Choose the desired action when the piping works under the then section.
Click SAVE.
To add a custom script to redirect to a new page in the Survey End page:
Go to Builder>Settings>Survey End Page and scroll down to the Default end page section. Choose the Redirect to a new page option.
Click the Insert Variable icon, scroll down, and select Javascript Snippet.
Add the custom script required for piping, then test run the code to ensure it works. If it works, click SAVE.
Add the piping parameter to the URL to which the survey should redirect, then click SAVE.
For adding a custom script for a Custom Message in the Survey Disqualification Page, follow the steps below:
Go to Builder>Settings>Survey Disqualification Page and choose the Custom Message option.
Click Insert Variable, scroll down, and choose Javascript Snippet.
Add the custom script required for piping in the window that opens, then test run the code to ensure it works. Then click SAVE.
To add a custom script to redirect to a new page in the Survey Disqualification page:
Go to Builder>Settings>Survey Disqualification Page and select the Redirect to a new page option.
Click the Insert Variable icon, scroll down, and select Javascript Snippet.
In the window that opens, add the custom script required for piping and test run the code to ensure it works. If it works, click SAVE.
Add the piping parameter to the URL to which the survey should redirect, then click SAVE.
The following keywords are restricted to be saved in JavaScript :
console | window | alert | this |
self | new | class | await |
worker | debugger | async | import |
export | try | catch | throw |
finally | resolve | reject | super |
extends | pause | play | then |
remove | object | function | promise |
globalThis | image | xmlhttprequest | xmldocument |
geolocation | formdata | file | event |
websocket | urlpattern | formdata | document |
sessionstorage | localstorage | cookie | clearinterval |
usb | cleartimeout | postmessage | prompt |
setintervals | settimeout | cache | bluetooth |
payment | otp | database | global_object |
eval | arguements | global-fucn | canvas |
strict | audio | navigation | navigator |
While using script conditions in URL Parameter, you must enter the param value inside square brackets []. For example, application. survey.urlparam ["userName"] in JavaScript, because special characters are not allowed in the JSON key in dot notation.
To avoid syntax errors, javascript code should contain javascript syntax, and it should always end either with a semicolon or be properly wrapped inside curly braces.
A sample reference Java script snippet code to achieve a simple arithmetic operation :
The given code combines arithmetic operations and conditional statements to make decisions based on the values of certain variables or expressions.
var rating = application.survey.question.C.response + application.survey.question.D.response;
if (application.survey.question.A.response == "Single"
application.survey.question.B.response == 2)
{
return true;
}
else if (rating > 10)
{
return true;
Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.
If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.
You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.