title: Supplying string parameters that may contain special characters to a javascript function
body: <p>I need to pass strings that <strong>may</strong> contain special characters to a Javascript function as below.</p>
  
  <pre><code>function setEditMode(countryName, countryCode)
  {
      document.getElementById("txtCountryName").value=countryName;
      document.getElementById("txtCountryCode").value=countryCode;        
  }
  
  &lt;input id="txtCountryName" name="txtCountryName" type="text" maxlength="50"/&gt;&lt;br/&gt;
  
  &lt;input id="txtCountryCode" name="txtCountryCode" type="text" maxlength="2"/&gt;&lt;br/&gt;               
  
  &lt;input type="button" value="Submit" id="btnEdit" name="btnEdit" onclick="setEditMode('&amp;#039;xx&amp;#039; &amp;#034;yy&amp;#034; # $', '&amp;#034;&amp;#039;');" /&gt;
  </code></pre>
  
  <p>When the button is clicked the two parameters of type string that contain special characters need to be supplied to the <code>setEditMode()</code> Javascript function. The strings need to be escaped. I have tried using the <code>escape()</code> function but it didn't work. Is there a way to pass such parameters to a function? (I'm dealing with JSP).</p>
  
  <p>[Those parameters of the <code>setEditMode()</code> function correspond to <code>'xx' "yy" # $</code> and <code>"'</code>
  respectively].</p>