1

I have a string in my Visualforce code like so:

String strGood = '';
strGood = item.getGoodPercentage().toPlainString();

I would like to javascript encode the string. I understand that there is the JSENCODE method that can be used on the page itself, but is there an equivalent that can be used in the Visualforce class? If not what is the best approach?

2 Answers 2

3

The JSENCODE function is available in Visualforce. Check out http://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_functions.htm.

If you have the variable jsString in your controller, you can use the following to set the string to a JS variable with the corresponding escaping:

var myVar = {!JSENCODE(jsString)};
Sign up to request clarification or add additional context in comments.

Comments

2

I presume you mean you want to URL encode this string. There is an Apex function called EncodingUtil that you can use for this purpose.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.