You need to sign in to do that
Don't have an account?

A problem with apostrophe in Custom Javascript button
Hi All,
Can anyone tell me how I can load a string in Javascript when the variable contains an apostrophe. For example I would like to load oppName with the Opportunity name where the Opportunity name is Bob's Country Bunker Inc. Using var oppName = '{!Opportunity.Name}'; fails. Any help would be much appreciated, thanks
Can anyone tell me how I can load a string in Javascript when the variable contains an apostrophe. For example I would like to load oppName with the Opportunity name where the Opportunity name is Bob's Country Bunker Inc. Using var oppName = '{!Opportunity.Name}'; fails. Any help would be much appreciated, thanks
Doh! Just found out that if I enclose {!Opportunity.Name} with double quotes instead of single quotes I can read in the string.
Best Regards
All Answers
Can you post the code? I tried alerting a javascript var which was assigned a field value having a apostrophe and it worked
The following code fails:
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")}
var s = '{!Opportunity.Name}';
It generates an alert box with the message "A problem with the OnClick JavaScript for this button or link was encountered: Unexpected identifier" if run in Chrome and the error "A problem with the OnClick JavaScript for this button or link was encountered: missing ; before statement" in Firefox.
I have tried using the custom button on several Opportunities and the alert is only generated on Opps that have an apostrophe in the field.
Best Regards
Doh! Just found out that if I enclose {!Opportunity.Name} with double quotes instead of single quotes I can read in the string.
Best Regards
var url = '/a0Y/e?retURL={!Opportunity.Id}&RecordType=01250000000J5bY&ent=01I50000000QcYO&CF00N50000002DH5h={!Opportunity.Account}&CF00N50000002DH5h_lkid={!Opportunity.AccountId}&CF00N50000002DH5v={!Opportunity.Name}&CF00N50000002DH5v_lkid={!Opportunity.Id}&CF00N50000002DH5i_lkid={!$User.Id}&CF00N50000002Dnha={!Opportunity.Primary_Third_Party_Acc__c}& CF00N50000002Dnha_lkid={!Opportunity.Primary_Third_Party_Account_ID__c}&CF00N50000002DX3C={!Opportunity.Primary_Third_Party_Contact__c}&CF00N50000002DX3C_lkid={!Opportunity.Primary_Third_Party_Contact_ID__c}&CF00N50000002DH5i={!$User.FirstName}+{!$User.LastName}&00N50000002DK1t={!TODAY()}';
window.open(url,'_self');
}
else{
alert('You don\'t have permission to access this button');
}
Getting the same error
A problem with the OnClick JavaScript for this button or link was encountered:
missing ; before statement
can you help me plz?