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 Mar 24 '16 at 12:16

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.