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
Drew1815Drew1815 

How to handle double-quotes and single-quotes in a Merge Field

Hi,
   I am running into a javascript issue when a specific merge field, Account Name, has both single and double-quotes in its name. So, my sample code looks like:

SControl Code
var accountName = "{!Account_Name}";

After SControl dynamically replaces the Merge Field values
var accountName = "Aethn"a Home Products";
***This causes JavaScript issues as the inner " is not escaped. So I receive a syntax error.

If I wrap the the merge field syntax with single-quotes (var accountName = '{!Account_Name}'), I will resolve the issue for double-quotes within the Account Name, but then I will get errors if a single-quote is in the Account Name.

I have a javascript function that escapes a single-quote and double-quotes, but I can't execute that method since the javascript doesn't even execute due to the syntax error mentioned above.

Question - How can I store a merge field value in javascript that contains BOTH an single-quote and double-quote?


The_FoxThe_Fox
Hello,

you have two possibilities:
First, you query salesforce as usual not passing the merge field,
Second, you put your merge field in an hidden div like <div id="hiddenMergeFields"> and you get the value of the innerHTML of the div for further use

Regards