Using Javascript

Astoria supports using javascript to customize Webform documents.

Javascript is often used to handle tasks such as form validation.

For general information on the javascript commands available for ACS administrators, see webforms.js in the Webforms application directory. By default, this is C:\ Program Files\Astoria Software\WebForms\applicationName.

Usage Example

findElementByName(fieldName). This method returns the form element object with the specified name. The name of the element matches the name of the field definition document. For example, if your Webform document contains a field called "address", then calling findElementByName("address") returns the form element object for the address field. You can then perform javascript operations on this field.

Example 1:

field = findElementByName("address");

if (field.value == "123 Main Street")

{

alert("Address is too generic");

}
Note: This method does not work with fields in repeat groups. With repeat groups, there can be multiple values for each field. To get the values of repeat group fields, you must calculate the offset of the repeat group in the form, and the offset of the field in the repeat group. In the example below, the repeat group is the 5th item in the Webform, and the desired field/value pair is the 3rd field in the repeat group.

Example 2:

var vn = form.name + "_field_5_values";

var values = eval(vn);

// 'values' contains all of the values of all of the fields in the repeat group.

// the loop below loops through each set of values in the repeat group.

for(var i=0; i<values.length; i++)

{

// to get the value of the Nth field, access 'fields[N-1]'

// the code below finds the value of the 3rd field

var fields = values[i];

var value = fields[2].getFieldValue();

}