"тнιѕ вℓσg ¢συℓ∂ ѕανє уσυя мσηєу ιƒ тιмє = мσηєу" - ∂.мαηנαℓу

Wednesday 30 March 2011

Checkbox onChange event is not working properly in CRM 2011 OR Checkbox click Issue in CRM 2011

In CRM 2011, it was found that the checkbox is not working as per our expectation. As we all know, the twooptionset(bit field) attribute type is converted to a checkbox on the form. Now consider a scenario. When you tick or untick the checkbox we would like to execute some code (Say hide a control). But the code written in Onchange is not fired until we leave the checkbox. So if we click outside of checkbox or if we press tab button, then only code changes would reflect. Whereas our expectation is always an immediate change when we tick or untick the checkbox. The following workaround could be applied to the checkbox. This code could be written in any event which is prior to Onchange event of the checkbox. So obviously we should prefer OnLoad event of the form in most of the cases.

crmForm.all.yourattributename.onclick = function ()  {
crmForm.all.yourattributename.FireOnChange();
};

Eg: If you have a checkbox called new_mycheckbox then

In Page Load (OR any event which happens before Onchange of checkobx) write this code

   crmForm.all.new_mycheckbox.onclick = function () {

            crmForm.all.new_mycheckbox.FireOnChange();

        };
and then write the code (hide control or whatever ...) in OnChange event of checkbox

3 comments:

  1. Hi..

    Did this work for anyone ? I think there is no onclick event for a radio button/check box...so this solution is not working for me.

    any help would be greatful.

    ReplyDelete
  2. worked perfectly for me. Just add a function with the line of code for each checkbox and then trigger that function on the form onload event. After that, the checkboxes triggered immediately when checked or unchecked.

    Great tip. thanks.

    ReplyDelete
  3. Try this:

    1. include jQuery library to the form
    2. OnLoad, attach the On Click event:
    $('#new_checkbox').click(FunctionCheckboxOnClickHanlder);

    Cheers,

    Taj

    ReplyDelete