Scripting Form Fields with the Onchange field

Onchange attribute of a Field
Description: code that is executed when the value of the field is changed in the Form Edit screen.
Where to enter code: Template Field Edit in web account / Onchange field
Syntax: you can access the new value of the field in the ‘value’ variable. The ‘formid’ variable contains the unique identifier of the current form. The code must return true or 1 for the field value to be updated.

Example: Change the end date field F2 based on the value of start date field F1. Enter the following script in the Onchange field:

var d = new Date(new Number(value));
var value2 = d.setFullYear(d.getFullYear()+1);
_valueObj[‘F1’] = value;
_valueObj[‘F2’] = value2;
var values = JSON.stringify(_valueObj);
Query.updateId(“Forms.forms”, formid, ‘value’, values);
History.reload();
return 0;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s