Scripting - *Validation Scripting, JavaScript

Custom validation scripting code can be inserted to the Validation script box to prevent users from continuing, deciding what page to jump to, and for advanced question validation. The Validation script box is located on the right side of the screen when you select a Section title object. Press the JS/Perl button to toggle between Javascript style and Perl style syntax. You can also view the Validation script box from the Validation tab of the advanced question options for Section title objects.

Custom JavaScript validation code is used in combination with the compiled CGIs. Custom Perl validation code is used in combination with the Perl CGIs.

All of the custom validation scripting code should be put into the projectname.val file.

Local Variables

Local variables in the .val file start with an underscore. So, if you want to create a temporary variable use something like _count to represent the variable. Otherwise, the variable will become part of the survey and be passed from page to page. If this is done, a hidden field will need to be put in the form.

If... Else...:

if(condition)
{
[statements]
}
else
(line break needed- nothing on this line after the else is evaluated)
{
(line break needed)
[statements] (line break needed)
}
(space usually necessary)

Using Page Variables:

Write page variables to temp variables before evaluating with an operator. Check-all-that-apply questions field names are followed by an underscore and the response code

(_PAGEWARN =~ 'foo')
It is better to use: HAS
(_PAGEWARN HAS 'foo')

Evaluating field value of Check-all, single choice, questions:
/fieldname/ eq ...

Functions:

Use special functions in the validation file to perform tasks. Some of these functions include:

runReport

Process a .rep file and return the HTML code that it outputs.

sendMail

Send an email message to the specified recipient. Note: the EMAILSERVER parameter must be in the .ini file for sendMail to know what email sever to use.

ShowPage

Decide what page is shown next. The page name is going to be "page" then the name of the Section title that starts that page. For example, if the page I wanted to go to is named "Q2", I would put in "pageq2". The last page of a multiple page survey does not check for the ShowPage; it will automatically submit.

Example:

_msgtext = runReport('project.rep','project2.rep');
sendMail('raosoft@raosoft.com','EZSurvey submissions',_msgtext);

if(Q35 =='2')
{
if(/Q36/ ne '')
     {
_PAGEWARN += 'notpossible,';
     }
}

See also...