+ Start a Discussion

Special characters (&) on strings passed to popup page

I’m running into a problem passing a string with an & to a popup page. It causes the string to be truncated at the point of the "&" when I use the string within the popup page controller. I presume I’m dealing with special character issues in the string. Looked around and couldn’t find anything on how to deal with special characters when passing parameters from html to a new page. Do I need to prevent special characters in the string (i.e. check with CONTAINS(&) ) when string is originally entered, or can I escape special characters in this case? If I have to prevent, any other special characters I need to prevent?


Here’s where I set the onclick and pass parameters to javascript function “drilldown”:



              <a href="#" onclick="return drilldown('{!cell.column}','{!cell.value}','{!cell.competency}','{!cell.maturity}','{! cell.location}')">{!cell.value}</a>                                



The location with the & is “Spokane R&D”. When the html is rendered, it replaces the & with “&amp:” as shown below:



         <a href="#" onclick="return drilldown('4','0','AAA','Best Practice','Spokane R&amp;D')">0</a>                                 



This is the javascript function “drilldown”:


  <script type="text/javascript">

       function drilldown(column,cellvalue,competency,maturity,location){

       var w=window.open('/apex/CompetencyDrillDownPage?colVar='+column +'&cellVar='+cellvalue+'&compVar='+competency+'&matVar='+maturity+'&locVar='+location,target='_blank')

       return False;




From the new page controller:


    PageReference PageRef = ApexPages.currentpage();

    String column = PageRef.getParameters().get('colVAR');     

    String value = PageRef.getParameters().get('cellVAR');

    String competency = PageRef.getParameters().get('compVAR');

    String maturity = PageRef.getParameters().get('matVAR');

    String location = PageRef.getParameters().get('locVAR');


  public List<PracticeLocationJTN__c> getPracticesandChoices()


     System.debug(LoggingLevel.Info, 'xxxx location= '+location);


This is the output of the debug log:


08:40:05.140 (140336000)|USER_DEBUG|[31]|INFO|xxxx location= Spokane R



Saurabh DhobleSaurabh Dhoble

Make sure you replace & character with %26

that should take care of the encoding.


Thanks for you reply. I presume you mean to replace the "&" in the field after it is queried and provided to the visualforce page?  I tried this right after the query, and it still renders in the html with  "&amp;" in the web page <td> cell. "compsel" is the list resulting from the query of which location is a field that contains the ampersand.


for(Integer comidx=0;comidx<compsel.size();comidx++) {


Am I missing something?