2

I'm working with a Detail Page Button that executes OnClick Javascript. Most of the time it works just fine. However, in this particular instance, one of the merge fields in the script has a value of "St. John's"

I've tried...

var encoded = {!JSENCODE("St. John's")};  //Causes Error
var encoded = {!JSINHTMLENCODE("St. John's")};  //Causes Error

And these return "illegal character"

var encoded = {!URLENCODE("St. John's")};  //Causes Error

returns "missing name after . operator

I've also tried various combinations of escape() and encodeURI() but without success.

Ultimately I think I need to escape that .... I could probably make a formula field that replaces the unsafe characters, and use that result as a merge field in the OnClick Javascript. I'd much rather do it all in button if at all possible

Any suggestions? (not doing business in St. John's is not an option!)

1 Answer 1

3

You forgot the quotes on the outside:

var encoded = "{!JSENCODE("St. John's")}";

This would render as:

var encoded = "\"St. John\'s\"";
1
  • 1
    Well! That work's MUCH better. Thanx Fox! Now that I have a Javascript safe string, I can do whatever I need with it. Commented Mar 14, 2018 at 19:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .