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 10731 times.

Share your jQuery code snippets:

  • Get some recognition & a link back to your site.
  • Create your own code library.
  • Help your fellow developers, as they have helped you.

 

Submit | Browse

Most Recent jquery snippets

Most Viewed