jQuery Preserve textarea line breaks for AJAX call

By default, JavaScript will ignore textarea line breaks. This one-liner replaces them with their URL encoded values.
var preserved = $('textarea').val().replace(/\n\r?/g, '%0D%0A');
Posted by
Snippet Viewed 16018 times.

Share your jQuery code snippets:

  • Get some recognition & link back to your site.


Submit | Browse

Most Recent jquery snippets

Most Viewed