This article has been updated to correct links.
If you have been creating onChange scripts then you will possibly about know the quirk which requires you to use single quote marks (') rather than double (") quote marks when outputting strings.


window.alert('this field has changed') is correct

window.alert("this field has changed") is incorrect and will not work.

I have discussed this in detail in a previous article, "Quotations in onChange Scripts".

A bad way of working

I have come across people 'hijacking' this quirk to add in extra behaviour into the fields. By default screen definitions in Sage CRM let you only define onChange events for the fields but browser strcutures like fields can have many events defined in HTML - onmouseover, onblur, onclick etc.

The 'hijacking' trick looks like this. In the onChange script box start the code with a double quote (") and then add the additional code you want e.g.

" onMouseOver="window.alert('oops')";

If you try that example you'll find you will not be able to edit the field! Another is example is this:

" onclick="window.status = 'oops'";

This is a bad way of working! This is not just bad because of the messy hijacking of the way the screen is drawn but it is bad because the events are only added when the HTML input is drawn on the screen. Although events like onMouseOver are available to any tag if we add the event in this way to the onChange script it is only added to the screen when in Edit mode. Additional events added this way will will not be available in View mode!

A good way of working

I have discussed previously the way in which fields and field captions are clearly identifiable in clientside code.

For example see the article "Identification (ID) of Checkbox Fields in Clientside Code". 

We can use the _CaptXXXXX and _DataXXXXX naming convention to add events that are available whatever mode the screen is in. This code can be added into the custom content of the screen and the method will allow you to attach any event you need to any screen object.

if (window.addEventListener)
//firefox way of binding an event
window.addEventListener("load", testFunctionMozilla, false);
if (window.attachEvent)
//IE exclusive method for binding an event
function testFunctionMozilla() 
_Datacomp_name.addEventListener("onmouseover", testFunction2, false); 
function testFunctionIE() 
function testFunction2() 

I will leave it to you to decide why you may want to use additional events. 

For a discussion of screen mode in clientside script see the article "Detect Screen Mode (Client Side) for Company and Person Summary Screens".

AttachEvent has been discussed in the article "attachEvent and client side scripts".