title: Escaping single quotes in VB script >> Java script
body: <p>I have a classic ASP which is coded in VB script and it also has Java script code in the script tag.</p>
  
  <p>VS Script has an array and some row contains a single quote. And this VB Script array is being passed to Java script. As some string values contains single quotes, the webpage does not work after the string is passed to Java script.</p>
  
  <p>I tried to escape single quotes in VB script before passing to Java Script</p>
  
  <pre><code>Dim escapeInvalidString    
  escapeInvalidString = Replace(objrec.Fields("Name"), "'", """chr(39)""")
  vbStr = escapeInvalidString
  </code></pre>
  
  <p>Also tried</p>
  
  <pre><code>escapeInvalidString = Replace(objrec.Fields("Name"), "'", "''")
  </code></pre>
  
  <p>I tried in Java script without escaping in VB Script as well</p>
  
  <pre><code>var jsStr ="";    
  jsStr = '&lt;%= vbStr %&gt;'.replace(/'/g, "\\'");
  </code></pre>
  
  <p>Also tried this.</p>
  
  <pre><code>jsStr = '&lt;%= vbStr %&gt;'.jsStr.replace(/\"/g,'\\"');
  </code></pre>
  
  <p>I have a feeling that I need to escape single quotes in VB Script parts but the above did not work. Any tips would be very appreciated.</p>