Here is an example of how to use JavaScript within a CRM 3.0 form to combine the values of the First Name and Last Name fields and put the combined values into the Company field:

 

var firstName = crmForm.all.firstname.DataValue;
var lastName = crmForm.all.lastname.DataValue;
var companyName = "";
if (firstName != null)
{
companyName = firstName + " ";
}
if (lastName != null)
{
companyName = companyName + lastName;
}
if (companyName != null)
{
crmForm.all.companyname.DataValue = companyName;
}

This code needs to be placed into the OnChange event of the First Name and Last Name fields.

Note 1: Remember that JavaScript is case-sensitive so you must spell the form field names correctly or your code will either not function properly or it will generate a JavaScript error.

Note 2: Remember to publish the Entity after you have made modifications to the form. Otherwise your users will not see it.

For more information on using JavaScript within CRM 3.0, please review the CRM 3.0 SDK.

Revised 9/8/06 to incorporate checks to ensure we have valid data to add to the company name. Thanks to Matt Wittemann for the suggestion.