title: Escaping characters in javascript strings
body: <p>I thought that escaping quote characters in javascript was done by either using the other style of quote  </p>
  
  <pre><code>"xxx ' yyy"
  </code></pre>
  
  <p>or  </p>
  
  <pre><code>'xxx " yyy'
  </code></pre>
  
  <p>or using a backslash to quote them  </p>
  
  <pre><code>'xxx \' yyy\'
  </code></pre>
  
  <p>or  </p>
  
  <pre><code>"xxx \" yyy"
  </code></pre>
  
  <p>but that doesn't seem to work in the problem I am currently working on.</p>
  
  <p>The code I want to put in my generated HTML is:  </p>
  
  <pre><code>&lt;input type="text" value="MyValue" name="MyName" 
      onChange="MyFunction(this, 0, 99999, ['XXX', this.value, 'YYY']);"&gt;
  </code></pre>
  
  <p>The question is what escaping is needed for the string YYY?</p>
  
  <p>I thought escaping single quote (') would be fine, but then I would also need to escape double quote (") as that is the outer wrapper for the onChange code.</p>
  
  <p>Lets say the string I want for YYY is:  </p>
  
  <pre><code>SQ' DQ" LT&lt; GT&gt; AMP&amp;
  </code></pre>
  
  <p>so I tried outputting  </p>
  
  <pre><code>&lt;input type="text" value="MyValue" name="MyName" 
       onChange="MyFunction(this, 0, 99999,
           ['XXX', this.value, 'SQ\' DQ\" LT&lt; GT&gt; AMP&amp;']);"&gt;
  </code></pre>
  
  <p>but FireFox saw the "&lt;" as breaking the code</p>
  
  <p>Eventually, to keep FireFox happy, I had to use  </p>
  
  <pre><code>SQ\' DQ\x22 LT\x3C GT\x3E AMP\x26
  </code></pre>
  
  <p>i.e.  </p>
  
  <pre><code>&lt;input type="text" value="MyValue" name="MyName"
      onChange="MyFunction(this, 0, 99999,
          ['XXX', this.value, 'SQ\' DQ\x22 LT\x3C GT\x3E AMP\x26']);"&gt;
  </code></pre>
  
  <p>this is a heck of a lot more escaping than I had expected. Is it really necessary, or have I missed something more straightforward?</p>
  
  <p>Thanks.</p>