Skip to main content
Post a question

Notifications

Community site session details

Community site session details

Session Id :

Changing a Checkbox Attribute’s Functionality

Mitch Milam Profile Picture Mitch Milam

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.


This was originally posted here.

Comments

*This post is locked for comments