hub.eb?material_id=78&track_id=357

Event Owner


The event owner is the object that triggered the current event, e.g. Before Form events are owned by the Form, an On Click event triggered by clicking a button is owned by that Button Control.

A common use for this is to display messages with the Control that generated the message.

event.owner.addErrorMessage("An error has occurred!");

Steps


1

Create a new Form and add a Field to a page. Set the field name to fullName and the type to Character.

2

Add a Field Control for the fullName Field. Also add a Button Control and set the text to Check.

3

Create a new script, call it checkName and add the following code:

if (RegExp('^[A-Za-z ]+$').test(fields.fullName.value)) {
  event.owner.addInfoMessage('The name you have entered is valid.');
} else {
  event.owner.addErrorMessage('Please enter a valid name. Your name can only contain letters and spaces.');
}

log('End of script.');

Attach this script to the Button Control's On Click event.

4

Run the Form, enter a name and click the button.

When you enter a valid name, containing only letters and spaces, a success message will be shown and the text "End of script." will appear in the Server Log.

When you enter an invalid name, containing numbers or special characters, an error message will appear and the script will halt, preventing the log message from being shown.

Current Module

Related