When, i set value to a textarea (programatically) as below, my string containing carriage return character, is removed.
document.getElementById('id').value = '<UNICODE-WIN>\r\n<Version:12.1>';
document.getElementById('id').value; //'<UNICODE-WIN>\n<Version:12.1>'
//or
$("#id").prop('value', '<UNICODE-WIN>\r\n<Version:12.1>');
$("#id").val(); // '<UNICODE-WIN>\n<Version:12.1>
//or
$("#id").val('<UNICODE-WIN>\r\n<Version:12.1>');
$("#id").val(); // '<UNICODE-WIN>\n<Version:12.1>
As i, researched there is no solution to this problem, still looking for a way to handle this scenario.
\r\n is important for us.
As soon we set value for element, \r
gets replaced.
Any help will be great. Thanks for your time.
Researched alot on this but have no idea how to resolve this. These are browser level encoding/replacement. Just looking for a way to set this behavior off. Read Those and think there is no way. https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-textarea-api-value Difference between \n and \r? carriage return in textarea retrieved as line feed
Workaround: It seems that below will not work
$("#id").prop('value', '<UNICODE-WIN>\r\n<Version:12.1>');
$("#id").val(); // '<UNICODE-WIN>\n<Version:12.1>
But this will work for other custom prop (seems they specifically kill it.)
$("#id").prop('plaintextprop', '<UNICODE-WIN>\r\n<Version:12.1>');
$("#id").prop('plaintextprop'); // '<UNICODE-WIN>\r\n<Version:12.1>