You need to sign in to do that
Don't have an account?
Kenneth Daniels 9
Custom Button Javascript interminatedliteral
I am trying to use javascript to display an alert is certain conmditions are met. I am not a javascript programmer.
My code is as follows:
if ("{!Contact.Banned_Warning_Explanation__c}" == "")
{
alert ("{!Contact.FirstName}" + " " + "{!Contact.LastName}" + " is free to use the center.");
}
else
{
alert ("{!JSENCODE(Contact.Banned_Warning_Explanation__c)}");
};
The first part of this works, if the field is empty the correct message displays. The second part of the clause returns an unterminated literal error. I understand this relates to unhandled line termination characters for example. If the second alert is the only code used it works properly and will display the field even if it is multiline. When I included in the If..else structure is when this error started.
My code is as follows:
if ("{!Contact.Banned_Warning_Explanation__c}" == "")
{
alert ("{!Contact.FirstName}" + " " + "{!Contact.LastName}" + " is free to use the center.");
}
else
{
alert ("{!JSENCODE(Contact.Banned_Warning_Explanation__c)}");
};
The first part of this works, if the field is empty the correct message displays. The second part of the clause returns an unterminated literal error. I understand this relates to unhandled line termination characters for example. If the second alert is the only code used it works properly and will display the field even if it is multiline. When I included in the If..else structure is when this error started.
This should fix it.
(" ")use only Single quotes (' '). as follows.
if (!Contact.Banned_Warning_Explanation__c == ' ' )
{
alert ( !Contact.FirstName + ' ' + !Contact.LastName + ' is free to use the center.' );
}
else
{
alert ( !JSENCODE(Contact.Banned_Warning_Explanation__c) );
};
then try to execute again :)