Tech Support > Microsoft Windows > Windows CRM > Object Expected Error when using OnChange Jscript
Object Expected Error when using OnChange Jscript
Posted by Al on October 17th, 2006


I am trying to make an OnChange in Campaign Responses so that when the
user selects an address type the system will fill in the correct
address information from the contact record.

I keep getting the following error:

Line: 506
Char: 1
Error: Object expected
Code: 0
URL: http//myserver:5555/ma/campaignresponse/edit.aspx?partyid
{E4DAA83A-5C26-DB11-BDB0-000E0CE2BF3}
&partytype=2&partyname=John%
20Test&partyaddressused=&contactInfo=

The code I am using in the onChange for the new_selectaddress attribute
is:

// load the variables from the parent record

/*
address1business = parentForm.all.address1_name.DataValue;
address1line1 = parentForm.all.address1_line1.DataValue;
address1line2 = parentForm.all.address1_line2.DataValue;
address1city = parentForm.all.address1_city.DataValue;
address1state = parentForm.all.address1_stateorprovince.DataValue;
address1zip = parentForm.all.address1_postalcode.DataValue;
address1country = parentForm.all.address1_country.DataValue;
address2business = parentForm.all.address2_name.DataValue;
address2line1 = parentForm.all.address2_line1.DataValue;
address2line2 = parentForm.all.address2_line2.DataValue;
address2city = parentForm.all.address2_city.DataValue;
address2state = parentForm.all.address2_stateorprovince.DataValue;
address2zip = parentForm.all.address2_postalcode.DataValue;
address2country = parentForm.all.address2_country.DataValue;
var msg;
*/

debugger

var LoadEvent = crmForm.all.new_selectaddress.DataValue;

alert (LoadEvent);


var msg = "Contact name = " + parentForm.all.fullname.DataValue +
"\r\nAddress1 Name = " + address1business +
"\r\nAddress1 Line1 = " + address1line1 +
"\r\nAddress1 Line2 = " + address1line2 +
"\r\nAddress1 City = " + address1city +
"\r\nAddress1 State = " + address1state +
"\r\nAddress1 ZipCode = " + address1zip +
"\r\nAddress1 Country = " + address1country+
"\r\nAddress2 Name = " + address2business +
"\r\nAddress2 Line1 = " + address2line1 +
"\r\nAddress2 Line2 = " + address2line2 +
"\r\nAddress2 City = " + address2city +
"\r\nAddress2 State = " + address2state +
"\r\nAddress2 ZipCode = " + address2zip +
"\r\nAddress2 Country = " + address2country ;

alert (msg);

if (crmForm.all.new_selectaddress = "1) {
msg = "Selected Address type = " +
crmForm.all.new_selectaddress.DataValue;
}
/*
// If the user provided a Address Type
// set Campaign Response address info to Address1 from Parent record
if (crmForm.all.new_selectaddress == "1") {
crmForm.all.new_businessname = address1business +
crmForm.all.new_mailaddress = address1line1 +
crmForm.all.new_mailaddress2 = address1line2 +
crmForm.all.new_mailingcity = address1city +
crmForm.all.new_mailingstate = address1state +
crmForm.all.new_mailingzipcode = address1zip +
crmForm.all.new_mailingcountry = address1counrty;
}
/* else
// Set Campaign Response address info to Address2 from Parent Record
if (crmForm.all.new_selectaddress == "2") {
crmForm.all.new_businessname = address2business +
crmForm.all.new_mailaddress = address2line1 +
crmForm.all.new_mailaddress2 = address2line2 +
crmForm.all.new_mailingcity = address2city +
crmForm.all.new_mailingstate = address2state +
crmForm.all.new_mailingzipcode = address2zip +
crmForm.all.new_mailingcountry = address2counrty;
}
else
if (crmForm.all.new_selectaddress == "3" &&
crmForm.all.new_mailingaddress == "" &&
crmForm.all.new_mailingcity == "" &&
crmForm.all.new_mailingstate == "" &&
crmForm.all.new_mailingzip == "") {
// Tell the user what is wrong.
alert("Please provide a Mailing address for this person.");

// Give the control focus.
crmForm.all.new_mailingaddress.SetFocus();

// Cancel the save operation.
event.returnValue = false;
return false;
}
*/

Please note the script works fine up through the second alert.

Any help will be much appreciated.

Al

Posted by Michael Höhne on October 17th, 2006


Unless I have overseen an alert, the second one is alert (msg);. The code
following that line has some errors:

if (crmForm.all.new_selectaddress = "1) {
msg = "Selected Address type = " +
crmForm.all.new_selectaddress.DataValue;
}

The first line of this block should be

if (crmForm.all.new_selectaddress.DataValue == "1") {

You're not using a comparison here, it's an assignment (one equal sign is
missing) and the string constant ("1") is not closed in your code. Further
you're missing the DataValue property.

--
Michael

Web: http://www.stunnware.com/crm2
Feed: http://www.stunnware.com/crm2/atom.aspx

----------------------------------------------------------

"Al" <allen@pembcons.com> schrieb im Newsbeitrag
news:1161106282.834164.304430@b28g2000cwb.googlegr oups.com...