Script-based validation in the Data Validation developer sample form

Microsoft Office InfoPath

Show All Show All

Script-based validation in the Data Validation developer sample form

Script-based validation is specified in the business logic script file associated with a Microsoft Office InfoPath 2003 form, and it provides more flexibility than custom validation or schema-based validation. Using script-based validation, you can specify when a field should be validated (for example, when the user first types data into a field, after the user leaves a field, or after data is validated by the schema). You can also write script that runs when a form is opened or when the user switches views. The script you write can perform a variety of functions, including comparing fields, calculating values, showing error messages, updating values, and revising other fields.

Note  InfoPath supports writing script in Microsoft VBScript and Microsoft JScript. However, you cannot mix the scripting languages used within a single form.

To create script-based data validation, you use InfoPath design mode to create an event handler (also called an event function), and then you write scripting code for the event handler using the Microsoft Script Editor (MSE). For each event handler that you create, InfoPath places an entry in the form definition (.xsf) file that contains the name of the event handler and the XML Document Object Model (DOM) node that the event handler is associated with.

Because the event handler is referenced in the .xsf file, you cannot create a new event handler entirely from within MSE— you must initially create the event handler in InfoPath design mode. Since InfoPath is used to create the declaration of the event handler, you cannot modify the event handler name or its arguments once it has been created.

ShowEvent handlers in the form definition file

ShowScript-based event handlers and functions

ShowUsing the DataDOMEvent object