I have the following piece of code

<button type="button" onclick="SetApprove('{!myPA.P__c}'); jQuery('#approvePName').text('{!myPA.P__r.name}');  jQuery('#approvePType').text('{!myPA.P__r.P_Type__c}');  **jQuery('#approvePCT').text('{!myPA.Pub__r.Curr_Tar__c}');** jQuery(document.getElementById(pAIdForApprove)).val('{!myPA.Id}'); viewApproveForm();return false;">Approve</button>

//this part below is within a jquery popup div

<label for="checkbox">Yes I <b>Approve</b>
        <b id="approvePType">Dec</b> for submission to <b id="approvePCT">TBD</b>

Here what is happening is that myPA.Pub__r.Curr_Tar__c has special characters so the jquery popup div is not showing. can anyone tell me an alternative to the jquery text method?

  • Try jQuery('#approvePCT').text('{!JSENCODE(myPA.Pub__r.Curr_Tar__c)}');
    – Sam
    Commented Mar 24, 2016 at 12:16

1 Answer 1


Use visualforce JSENCODE function



Encodes text and merge field values for use in JavaScript by inserting escape characters, such as a backslash (), before unsafe JavaScript characters, such as the apostrophe (').


{!JSENCODE(text)} and replace text with the merge field or text string that contains the unsafe JavaScript characters.

You must log in to answer this question.

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