-
Changing a Checkbox Attribute’s Functionality
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,773 views3 responses to “Changing a Checkbox Attribute’s Functionality”
-
Great tip , thanks for publishing .
-
Including External JavaScript Files - ICU-MSCRM - Life support for the heartbeat of your business June 4th, 2009 at 09:37
[...] 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 [...]
-
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
-




