OnClick Event

Microsoft Office InfoPath

Show All Show All

OnClick Event

Occurs when a button control is clicked within a view in a Microsoft Office InfoPath 2003 form.

Function ScriptID::OnClick(ByRef eventObj As DocActionEvent)

eventObj Required DocActionEvent. A reference to the DocActionEvent object.

Remarks

This event handler does not allow users to cancel an operation.

Note  The OnClick event for the InfoPath button control is the only control event that is supported.

Example

In the following example from the Events developer sample form, the OnClick event handler is used to perform data validation on some of the fields contained in the New Customer view when a user clicks a button to switch to another view:

    function btnSwitchContact::OnClick(eventObj)
{
   if (XDocument.View.Name == "New Customer")
   {
      if (XDocument.DOM.selectSingleNode
         ('/Customers/CustomerInfo/CustomerName').text == ""
         && XDocument.DOM.selectSingleNode
         ('/Customers/CustomerInfo/CustomerID').text == "")
      {
         XDocument.UI.Alert("The Customer Name and ID must " +
            "be filled in prior to switching the view.");
         return;
      }
      else if (XDocument.DOM.selectSingleNode
         ('/Customers/CustomerInfo/CustomerName').text == "")
      {
         XDocument.UI.Alert("The Customer Name must be filled " +
            "in prior to switching the view.");
         return;
      }
      else if (XDocument.DOM.selectSingleNode
         ('/Customers/CustomerInfo/CustomerID').text == "")
      {
         XDocument.UI.Alert("The Customer ID must be filled in " +
            "prior to switching the view.");
         return;
      }
   }
   XDocument.View.SwitchView('Contact Customer');
}