Have you tried adding a xml:space="preserve"
attribute and use just plain normal line breaks?
views:
2349answers:
3Why not use regular linebreaks? Those work just fine.
If you want <br />
to appear, you need to encode those entities:
<br />
From the DTD:
<!ELEMENT TEXTAREA - - (#PCDATA) -- multi-line text field -->
In the XHTML code of your page, a <textarea>
can only contain text (#PCDATA
), and you cannot nest any XHTML elements within the <textarea>
.
Your questions seems to show two different things. The image shows "<br />
" written into a <textarea>
, while the message from the W3C Validator is referring to a <br />
element written into the XHTML of your page within the <textarea>
element.
In the first case, having "Test<br />line break
" appear to the user in the text area is done by using the appropriate entities, just as altCognito wrote:
<textarea>Test<br />line break</textarea>
Anything that's being entered by the user that is then redisplayed within a <textarea>
on a new page should be encoded (i.e., use entities for &
, "
, '
, <
, and >
).
If want to display a user's entry:
Test
<br />
line break
...as...
Test
line break
...within another text area, then you will need to parse what has been entered into the original <textarea>
and replace the user-entered <br />
s with normal line breaks. See Lucero's answer.