There might be situations where you’ll need to perform the same actions/calculations (via javascript) on different form events. Code duplication is always a bad idea so you could either include an external javascript file with your function or create the function in your form’s load event as follows:
CalculateAge = function()
{ if(crmForm.all.new_dateofbirth.DataValue != null)
{ // Your javascript logic
}
}
You can then call this function from any event on the same form. For example I could call this function right after creating it on the load event to ensure the age is always updated when the record is opened, and I can also call it from my date of birth field’s change event. To call the event, I would use this line: