Click to Rate and Give Feedback
MSDN
MSDN Library
Microsoft Dynamics
 Field Events: OnChange
Field Events: OnChange
banner art

The OnChange event occurs when the data in a form field has changed and focus is lost. Data in the field is validated before and after the OnChange event.

All fields support the OnChange event.

Note   Although the Status field supports the OnChange event, the field is read-only on the form so the event cannot occur through user interaction. Another script could cause this event to occur by using the FireOnChange method on the field.

Example

The following code example shows how to format basic U.S. phone numbers. This method supports 7-digit and 10-digit numbers, for example, (410) 555-1212. In the code the expression '"4105551212".length' is equivalent to 10.

// Get the field that fired the event.
var oField = event.srcElement;

// Validate the field information.
if (typeof(oField) != "undefined" && oField != null)
{
// Remove any nonnumeric characters.
  var sTmp = oField.DataValue.replace(/[^0-9]/g, "");

// If the number has a valid length, format the number.
  switch (sTmp.length)
  {
    case "4105551212".length:
      oField.DataValue = "(" + sTmp.substr(0, 3) + ") " + sTmp.substr(3, 3) + "-" + sTmp.substr(6, 4);
      break;

    case "5551212".length:
      oField.DataValue = sTmp.substr(0, 3) + "-" + sTmp.substr(3, 4);
      break;
  }
}

Remarks

You can force the OnChange event to occur for a field from the Microsoft Dynamics CRM form OnLoad event or from the OnChange event of some other field. To do this, use the FireOnChange method.

For example, you may use the following sample script:

crmForm.all.YourFieldID.FireOnChange();

© 2008 Microsoft Corporation. All rights reserved.


© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker