Client-Side JavaScript
Script that you enter in the onSubmit and onClick tabs (see Adding Form Controls) is standard JavaScript that is executed by the client browser when the corresponding event occurs.
Within the context of these scripts, you can use the 'Form' variable to reference all elements on the form. For example, if the form contains a Choice element with field name 'Choice1' and a TextField element with field name 'TextField1', you can add an onSubmit script on the Choice1 element to set the value of TextField1:
Form.TextField1.value = Form.Choice1.value;
return true;
This script executes whenever a “submit” action occurs in the form (triggered by any form element). Although you can attach the 'onSubmit' script to any element, a given form should contain only a single 'onSubmit' script. To assign a submit action to a form element (other than a Button), enable the 'Submit on Change' option in the element's 'Properties' dialog box.
If the 'onSubmit' script returns “true,” the form data is sent on to the server; otherwise, it is not sent. This allows you to use client-side script to verify input values before the form is sent to the server. For example, the 'onSubmit' script below verifies the value entered in TextField1:
if (Form.TextField1.value < 10) {
return true; //send to server
}
else {
alert('Maximum value exceeded.');
return false; //do not send to server
}
Storing JavaScript in an External File
You can store client-side JavaScript function definitions in an external file. This JavaScript file must reside in the SREE Home directory (WEB-INF/classes, by default) or in one of its subdirectories, and must be registered by setting the 'replet.custom.js' property in the sree.properties properties. For example, if the function definition file is named 'JSFunctions.js' and resides in the 'WEB-INF/classes/JS' directory, register the file in sree.properties as follows:
replet.custom.js = JS/JSFunctions.js
The JavaScript file is imported into the report when the report loads so that functions defined in the file are accessible to client-side scripts (i.e., scripts in the HTML tab of Form elements).
| << Adding Form Controls | © 1996-2013 InetSoft Technology Corporation (v11.4) | 6.3.2 Processing a Form >> |