hub.eb?material_id=278&track_id=357

On Click Event


The On Click event is triggered when an end-user clicks on a supporting Control in the browser.

The following Controls support the On Click event:

  • Button.
  • Hyperlink.
  • Image.
  • Field.
  • Table, Image and Button Columns.
  • Tab Set and Tab.
  • Horizontal and Vertical Menus.
  • Menu Item and Dynamic Menu Items.

Before the event is triggered, Fields are updated with any data the end-user has entered above the Control that triggered the event.

Steps


1

Create a Form. Add a Field called myField and drag it onto the Page.

 

2

Add a Button Control underneath the new Field Control by dragging a Button Control from the Palette. Name the Button Control myButton.

3

Right-click on the Button Control and select Events . Under On Click click the button to create a new Script. Name the script checkMyField. Add the following code:

// check whether the field has a value
if(!fields.myField.value){
  // if there's no value show an error message
  event.owner.addErrorMessage("Please fill in the field.");
}
else{
  // otherwise show a success message
  event.owner.addInfoMessage("Success!");
}
4

Run the Form.

Click the button. If you have entered a value in the Page before clicking the button you will be shown a success message, otherwise you will be shown an error message.

5

Drag the Button Control above the Field Control.

6

Run the Form again.

Fill in a value and then click the button. Notice that the error message is displayed. This is because the Control that triggered the On-Click event (the Button Control) occurs before the Field Control and so myField wasn't updated with the value.

Current Module

Part of tracks

Related