title: Encode HTML before POST
body: <p>I have the following script, which encodes some of the value it receives propertly, but it does not seem to encode double quotes.</p>
  
  <p>How do I encode the full value properly before posting?</p>
  
  <pre><code>function htmlEncode(value){ 
      return $('&lt;div/&gt;').text(value).html(); 
  } 
  </code></pre>
  
  <p>The above script give me this:</p>
  
  <pre><code>&amp;lt;p&amp;gt;Test&amp;amp;nbsp; &amp;lt;span style="color: #ffffff"&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;span style="background-color: #ff0000"&amp;gt;1+1+1=3&amp;lt;/span&amp;gt;&amp;lt;/strong&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
  </code></pre>
  
  <p>I need it to give me this:</p>
  
  <pre><code>&amp;lt;p&amp;gt;Test&amp;amp;nbsp; &amp;lt;span style=&amp;quot;color: #ffffff&amp;quot;&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;span style=&amp;quot;background-color: #ff0000&amp;quot;&amp;gt;1+1+1=3&amp;lt;/span&amp;gt;&amp;lt;/strong&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
  </code></pre>
  
  <p>EDIT: Followup question:
  <a href="https://stackoverflow.com/questions/4899365/encoded-html-in-database-back-to-page">Encoded HTML in database back to page</a></p>