title: How to escape a single quote inside a JavaScript variable
body: <p>I am facing a problem like if I click the button nothing is happening. I looked into the <a href="http://en.wikipedia.org/wiki/Firebug_%28software%29" rel="nofollow noreferrer">Firebug</a> console. It's throwing an error in the second argument that I have passed.</p>
  
  <p>In the second argument the question is a string, so it is enclosed with single quotes, but the value attained from the server side also has single quotes (father's) so (s middle name?') is not considered by JavaScript and throws a syntax error. How do I avoid this?</p>
  
  <p><strong>Source Code:</strong></p>
  
  <p>JSP page code:</p>
  
  <pre><code>&lt;input type="button" id="btnSubmit" Value="Edit" onclick="return
         editSeqQuestion('&lt;%=QuestionId%&gt;','&lt;%=Question%&gt;','&lt;%=QuestionDataType%&gt;',
                         '&lt;%=AudioPath%&gt;','&lt;%=securityQuestionType%&gt;')" /&gt;
  </code></pre>
  
  <p>In browser, view page source:</p>
  
  <p>The code looks like:</p>
  
  <pre><code>&lt;input type="button" id="btnSubmit" Value="Edit" onclick="return
         editSeqQuestion('72','what is your first child's nick name?',
         'Alpha Numeric','nickname.wav','SecurityQuestion')" /&gt;
  </code></pre>
  
  <blockquote>
    <p>Error: <code>SyntaxError: missing ) after argument list</code></p>
  </blockquote>
  
  <p><img src="https://i.stack.imgur.com/K4mrQ.png" alt="Firefox Error Console"></p>