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

Escape single quote\apostrophe within a formula
Hi all,
I'm using the following case statement to within a VF page to adjust some language. Within one of the options is an apostrophe and I'm having difficulty escaping it.
Here's what I have:
{!case(MyOBJ__c.MyField__c, 'Any time',' at any time.', 'Based on Employer policy',' based on your employer\'s policy.', 'MERGE ERROR')}
Doing this results in "based on your employer\'s policy" being displayed on the page.
Using \\'s results in a nasty looking Error: EL Expression Unbalanced: ...
And for grins, using \\\'s results in "based on your employer\\'s policy"
Hi,
"JSENCODE" function in visual force page is used to encodes text and merge field values for use in JavaScript. It inserts escape characters, such as a backslash (\), before unsafe JavaScript characters, such as the apostrophe (').This should solve the issue faced by you. For more information you can refer visual force guide documentaion under the topic "Advanced functions".
Syntax: {!JSENCODE(text)} and replace text with the merge field or text string that contains the unsafe JavaScript characters.
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
I don't know the answer, but maybe this helps:
Check out Wes' discovery and workaround for escaping stuff on VF pages:
http://th3silverlining.com/2010/02/17/visualforce-ids-in-jquery-selectors/
Particularly this quote:
"Note 2: We have to escape the escape as the VisualForce parser seems to unescape the first escape :$"
Hi,
"JSENCODE" function in visual force page is used to encodes text and merge field values for use in JavaScript. It inserts escape characters, such as a backslash (\), before unsafe JavaScript characters, such as the apostrophe (').This should solve the issue faced by you. For more information you can refer visual force guide documentaion under the topic "Advanced functions".
Syntax: {!JSENCODE(text)} and replace text with the merge field or text string that contains the unsafe JavaScript characters.
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
I can see where it would work, but am currently having a problem with the apostrophe within the JSENCODE function.
JSENCODE('employer's')
How would I handle that?
I came here is a similar question. Here is a snippet that does not work when the account name contains the single quote (e.g. O'Brians Company)
Thanks to the hints above I got it to work with this code: