Newline character in HTML TextArea

534 Views Asked by At

With reference to the answers available under following question - What character represents a new line in a text area

The newline character in a textarea should be CRLF though entering data in a textarea with newline generates only \n as can be seen in the snippet below -

<textarea id="one" onchange="document.getElementById('contentdiv').innerText=JSON.stringify(document.getElementById('one').value)"></textarea>
<button onclick="document.getElementById('contentdiv').innerText=JSON.stringify(document.getElementById('one').value)">Read Content</button>
<div id="contentdiv"></div>

Are there references/changes in the defined standards for the textarea with respect to the changed behavior seen here?

1

There are 1 best solutions below

0
Ocean Overflow On BEST ANSWER

The link you've provided actually has an answer.

The textarea element value exists in three variants:

  1. the raw value as entered by the user, unnormalized; it may contain CR, LF, or CR LF pair;
  2. the internal value, called “API value”, where line breaks are normalized to LF (only);
  3. the submission value, where line breaks are normalized to CR LF pairs, as per Internet conventions.

Your case is number 2