Error while writing scripts on OnChange script section

By | January 25, 2012

Recently I came across a problem with OnChangeScript in sage CRM version 7.1. Somehow OnChangeScript for search select advanced fields doesn’t like the script to be on multiple lines!
i.e. Below written script doesn’t work:
id = document.EntryForm.comp_type.value;
alert (‘comp_type:’+id);

and Below written script works:
id = document.EntryForm.proj_companyid.value;alert (companyid :’+id);
First script gives the following error when you attempt to write the code on multiple lines. The observation is that the code written on multiple lines was not working, however single line was.
I never observed this issue as I always used to define the function in custom content box and call it from onchange script. Below is the approach that I follow.
1. Create a function definition in Custom Content.
<script language=’javascript’>
function ShowAlert()
{
id = document.EntryForm.comp_type.value;
alert (‘comp_type:’+id);
}
</script>
2. Call function from onchange script.
ShowAlert();
Sometimes right way of scripting also saves us from disaster. Happy scripting!!!