Announcements
Hi all,
I want to attach a onclick event on a bit field. Is there a supported way to do this in crm 2013?
Thank you
Jan
*This post is locked for comments
Hi Jan,
Yes- that's fairly straight forward to do. First you need to go to the customisation area and add a new web resource containing the javascript. You can either create this in notepad and upload the file or alternatively key it into CRM directly using the text editor.
A sample of the required javascript is given here- in this case this custom function shows the myhideablefield form item if the mycheckbox field is checked and hides it if it's unchecked.
// Show/Hide the hideablefield based on the mycheckbox field
function myOnClickEvent() {
var show = Xrm.Page.getAttribute("mycheckbox").getValue();
if (show == true) {
showField("myhideablefield");
} else hideField("myhideablefield");
}
The you need to "wire up" the event handler to this custom function.
To do this open the form containing the bit field you want to respond to.
From the form editor click form properties.
You will need to add the web resource file at the top of the events page where it says Manage libraries that are available in this form.
In the events section at the bottom of the form locate your checkbox control and select on change. Finally you click add here and reference the newly imported web resource file and the name you gave the function (in the above example the function was called myOnClickEvent)
That should get you up and running once you save and publish the customisation changes.
I'd also add depending on your prior experience with javascript, for simple scenarios you could also consider using business rules to achieve the same results- these are basically a 'no code' approach which can be done all in the UI.
Best of luck
John
use onchange event.
If my response is helps you, please mark as "Verified"
You change attach an onchange event to a boolean field if this is what you need.
André Arnaud de Cal...
293,309
Super User 2025 Season 1
Martin Dráb
232,162
Most Valuable Professional
nmaenpaa
101,156
Moderator