, , ,

Hello Everyone,

Today I was working on a form, where I was suppose to add a Jscript on the OnChange Event of the CheckBox.

Consequently, I created a Two-option field(Radio-button by default) and added the Jscript webresource on the Onchange Event of the same field. I checked my code and it was working perfectly fine as expected, further changed the Radio button to CheckBox.
But When I was checked the CheckBox, the OnChange Event didn’t fired at all until and unless I tabbed out of the field. This came out as quite a surprise to me.

I do remember facing the same problem back in CRM 4.0 as well but didn’t get time to write down the solution. Had to do some reading again and I’m writing it this time to remind myself in case same problem occurs in near future. 😉

So, after some reading and tryouts I figured out that CheckBoxex are handeled a bit differently in Dynamics CRM. The OnChange Event on a CheckBox will not fire until we click outside of CheckBox or tab off the field. And I was pretty sure that my client will not accept this odd behaviour. They would definitely be expecting an immediate change after the CheckBox is checked.

To solve this problem I simply tried to fire my code on OnClick Event of the Field rather than OnChange event.

  • Subsequently, I pasted the code below on OnLoad event of the form.
crmForm.all.new_field.onclick=function() {

But even this didn’t work out properly. My code was executing twice this time. 1st when the CheckBox was checked(which was expected of OnClick event) and again when I tabbed off the Field.

I finally found a workaround where I would change the focus of current field-control to another field after the execution of my code on OnClick event.

  • To setFocus on another field we use the following code below:

So I cancelled my OnChange Event and pasted my code on Onclick event of the field followed by SetFocus().

  • My Final Code was somewhat like below:
crmForm.all.new_field.onclick=function() {
//My Code

And Yes !!!  This time it was functioning just the way we were expecting it to be.

Hope that was Helpful.