Knowledge found and lost while working with Microsoft Dynamics CRM
RSS icon Home icon
  • Changing a Checkbox Attribute’s Functionality

    Posted on April 20th, 2009 Mitch Milam Print Print 3 comments

    Each CRM Form field has an OnChange event associated with it that allows you ( the developer ) to execute JavaScript when the user changes the value of the attribute.  This event is fired when you change the attribute’s value and you leave the field – by clicking or using the Tab key.

    In certain instances, I have had bit attributes on the CRM Form which are formatted to display as a Checkbox.

    I would like the JavaScript added to the OnChange event to be executed immediately upon the user clicking the checkbox and changing the value. NOT when the user leaves the field.

    Using the following code, you can add that functionality:

    function ClickMe()
    {
      crmForm.all.new_checkboxfield.FireOnChange();
    }
     
    crmForm.all.new_checkboxfield.attachEvent('onclick',ClickMe, false);

    How It Works

    In the Form’s OnLoad event:

    1)I create a small JavaScript function called ClickMe that does nothing more than call the OnChange event for the bit attribute we’re working with.

    2) I use the JavaScript function attachEvent to attach the ClickMe function to the onclick event of the attribute.

    Once this code is published, any time the user clicks the checkbox, it will execute the OnChange code for the attribute.

    If you need to add this functionality to additional attributes, just duplicate the above code.

    Customization, Dynamics CRM, Unsupported
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    1,773 views
     

    3 responses to “Changing a Checkbox Attribute’s Functionality”

    1. Great tip , thanks for publishing .

    2. [...] MyFunction, false);Check out Mitch Milam’s blog at http://blogs.infinite-x.net/2009/04/20/changing-a-checkbox-field/ for a look at how he used attachEvent.Taking this approach a step further, it sometimes makes sense [...]

    3. That didn't work for me. It was firing when I clicked the label not the check box.

      This did though
      var ckBox = document.getElementById("crmsales_includeinmonthlyreport");
      if (ckBox) {
      ckBox.attachEvent("onclick", OpportunityPage.includeinmonthlyreportOnChange);
      }

    Leave a reply