I recently encountered some difficulty firing a JavaScript event off when a bit field was marked as True. The following code worked fine when the bit field was a radio button on the form, but the event would not fire until I tabbed out of the field when I had the bit field formatted as a checkbox. This was in my onChange() event for the bit field.
hideField = function() {
if (crmForm.all.some_bit_field.DataValue == 1)
//Hide Some Fields
}
It came to my attention that checkbox-type bit fields are handled a bit differently in Dynamics CRM. The onChange () event for a checkbox will not be fired until we leave the field. This was a problem as the customer expected the field to show/hide immediately when the field was changed, not when we tabbed off the field.
To solve the problem we simply added some Event Handling code into the onLoad event area of our entity form. With this piece of code included, the field will show/hide as soon as the bit value changes, not when we tab off the field.
crmForm.all.your_checkboxfield.onclick = function() {
crmForm.all.your_checkboxfield.FireOnChange();
}
Using the code above, the onChange () event will fire TWICE: Once when the field is changed and once when we tab off the field. If this is a concern in your implementation you can use the following code in the onLoad() event to ensure the event only fires once (Remember to remove the code from the fields' onChange event is you use the code this way!)
crmForm.all.your_checkboxfield.onclick = function() {
//Existing onChange() code
}
Happy Coding!
JoeCRM
Latest posts by JoeCRM (see all)
- Populating Field Values in a Form Using a Query String in CRM 2011 - May 21, 2013
- How to Assign a Territory to a Lead in Dynamics CRM - May 17, 2013
- Out of the Box Report: Dynamics CRM User Summary - May 16, 2013




