Perform a replace operation to verify that \r is before \n :
str = str.replace(/\r?\n/g, "\r\n");
Fiddle
Browsers use \r\n for line breaks, although modern browsers such as Chrome and Firefox can also handle \n Unix-style line breaks. IE8 requires proper line breaks \r\n , which also work in all other browsers.
And as @epascarello pointed out, use .val() to control the textarea value property.
source share