function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kenneth Daniels 9Kenneth 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.
Gaurav KheterpalGaurav Kheterpal
The unterminated literal error means that your double quotes are not matching or escaping properly. Based on what you mentioned, I would recommend changing the last line to use single quotes

 
alert ('{!JSENCODE(Contact.Banned_Warning_Explanation__c)}');

This should fix it.

 
Yogesh Dighe.Yogesh Dighe.
Do not use Double quotes anywhere in your code. (" ")
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 :)