กรณีเราต้องการขึ้นบรรทัดใหม่ใน textarea ในที่นี้จะแสดง 3 กรณ๊
คือ
1.ข้อมูลจากตัวแปร ต้องการแสดงใน textarea แบบขึ้นบรรทัดใหม่ตามต้องการ จะแทรก
ด้วยเครื่องหมาย \r\n ไว้ก่อนข้อความที่ต้องการขึ้นบรรทัดใหม่ แล้วนำค่าไปแสดงใน textarea
ตัวอย่าง โค้ด
<?php $data="line 1\r\nline2"; ?> <textarea name="textarea" id="textarea2" cols="45" rows="5"><?=$data?></textarea>
2. ข้อมูลที่กำหนดค่าเข้าไปใน textarea โดยตรง จะแทรกด้วย Special Characters ไว้ก่อนข้อความที่ต้องการขึ้นบรรทัดใหม่
ตัวอย่าง โค้ด
<textarea name="textarea" id="textarea1" cols="45" rows="5">line 1 line 2 line 3</textarea>
3. ข้อมูลที่ต้องการแสดงใน textarea ด้วย javascript (ในที่นี้ใช้ jQuery) จะแทรก
ด้วยเครื่องหมาย \r\n ไว้ก่อนข้อความที่ต้องการขึ้นบรรทัดใหม่
ตัวอย่าง โค้ด
<textarea name="textarea" id="textarea3" cols="45" rows="5"></textarea> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> <script type="text/javascript"> $(function(){ $("#textarea3").val("line 1\r\nline 2"); }); </script>
Special Characters in HTML
left single quote | ‘ | ‘ | |
right single quote | ’ | ’ | |
single low-9 quote | ‚ | ‚ | |
left double quote | “ | “ | |
right double quote | ” | ” | |
double low-9 quote | „ | „ | |
dagger | † | † | |
double dagger | ‡ | ‡ | |
per mill sign | ‰ | ‰ | |
single left-pointing angle quote | ‹ | ‹ | |
single right-pointing angle quote | › | › | |
black spade suit | ♠ | ♠ | |
black club suit | ♣ | ♣ | |
black heart suit | ♥ | ♥ | |
black diamond suit | ♦ | ♦ | |
overline, = spacing overscore | ‾ | ‾ | |
leftward arrow | ← | ← | |
upward arrow | ↑ | ↑ | |
rightward arrow | → | → | |
downward arrow | ↓ | ↓ | |
trademark sign | ™ | ™ | ™ |
unused | �-  | ||
horizontal tab | 	 | ||
line feed | | ||
unused |  | ||
space |   | ||
exclamation mark | ! | ! | |
double quotation mark | " | " | " |
number sign | # | # | |
dollar sign | $ | $ | |
percent sign | % | % | |
ampersand | & | & | & |
apostrophe | ' | ' | |
left parenthesis | ( | ( | |
right parenthesis | ) | ) | |
asterisk | * | * | |
plus sign | + | + | |
comma | , | , | |
hyphen | - | - | |
period | . | . | |
slash | / | ⁄ | / |
digits 0-9 | 0- 9 | ||
colon | : | : | |
semicolon | ; | ; | |
less-than sign | < | < | < |
equals sign | = | = | |
greater-than sign | > | > | > |
question mark | ? | ? | |
at sign | @ | @ | |
uppercase letters A-Z | A- Z | ||
left square bracket | [ | [ | |
backslash | \ | \ | |
right square bracket | ] | ] | |
caret | ^ | ^ | |
horizontal bar (underscore) | _ | _ | |
grave accent | ` | ` | |
lowercase letters a-z | a- z | ||
left curly brace | { | { | |
vertical bar | | | | | |
right curly brace | } | } | |
tilde | ~ | ~ | |
unused | - • | ||
en dash | – | – | |
em dash | — | — | |
unused | ˜- Ÿ | ||
nonbreaking space |   | | |
inverted exclamation | ¡ | ¡ | ¡ |
cent sign | ¢ | ¢ | ¢ |
pound sterling | £ | £ | £ |
general currency sign | ¤ | ¤ | ¤ |
yen sign | ¥ | ¥ | ¥ |
broken vertical bar | ¦ | ¦ or &brkbar; | ¦ |
section sign | § | § | § |
umlaut | ¨ | ¨ or ¨ | ¨ |
copyright | © | © | © |
feminine ordinal | ª | ª | ª |
left angle quote | « | « | « |
not sign | ¬ | ¬ | ¬ |
soft hyphen | ­ | ­ | |
registered trademark | ® | ® | ® |
macron accent | ¯ | ¯ or &hibar; | ¯ |
degree sign | ° | ° | ° |
plus or minus | ± | ± | ± |
superscript two | ² | ² | ² |
superscript three | ³ | ³ | ³ |
acute accent | ´ | ´ | ´ |
micro sign | µ | µ | µ |
paragraph sign | ¶ | ¶ | ¶ |
middle dot | · | · | · |
cedilla | ¸ | ¸ | ¸ |
superscript one | ¹ | ¹ | ¹ |
masculine ordinal | º | º | º |
right angle quote | » | » | » |
one-fourth | ¼ | ¼ | ¼ |
one-half | ½ | ½ | ½ |
three-fourths | ¾ | ¾ | ¾ |
inverted question mark | ¿ | ¿ | ¿ |
uppercase A, grave accent | À | À | À |
uppercase A, acute accent | Á | Á | Á |
uppercase A, circumflex accent | Â | Â | Â |
uppercase A, tilde | Ã | Ã | Ã |
uppercase A, umlaut | Ä | Ä | Ä |
uppercase A, ring | Å | Å | Å |
uppercase AE | Æ | Æ | Æ |
uppercase C, cedilla | Ç | Ç | Ç |
uppercase E, grave accent | È | È | È |
uppercase E, acute accent | É | É | É |
uppercase E, circumflex accent | Ê | Ê | Ê |
uppercase E, umlaut | Ë | Ë | Ë |
uppercase I, grave accent | Ì | Ì | Ì |
uppercase I, acute accent | Í | Í | Í |
uppercase I, circumflex accent | Î | Î | Î |
uppercase I, umlaut | Ï | Ï | Ï |
uppercase Eth, Icelandic | Ð | Ð | Ð |
uppercase N, tilde | Ñ | Ñ | Ñ |
uppercase O, grave accent | Ò | Ò | Ò |
uppercase O, acute accent | Ó | Ó | Ó |
uppercase O, circumflex accent | Ô | Ô | Ô |
uppercase O, tilde | Õ | Õ | Õ |
uppercase O, umlaut | Ö | Ö | Ö |
multiplication sign | × | × | × |
uppercase O, slash | Ø | Ø | Ø |
uppercase U, grave accent | Ù | Ù | Ù |
uppercase U, acute accent | Ú | Ú | Ú |
uppercase U, circumflex accent | Û | Û | Û |
uppercase U, umlaut | Ü | Ü | Ü |
uppercase Y, acute accent | Ý | Ý | Ý |
uppercase THORN, Icelandic | Þ | Þ | Þ |
lowercase sharps, German | ß | ß | ß |
lowercase a, grave accent | à | à | à |
lowercase a, acute accent | á | á | á |
lowercase a, circumflex accent | â | â | â |
lowercase a, tilde | ã | ã | ã |
lowercase a, umlaut | ä | ä | ä |
lowercase a, ring | å | å | å |
lowercase ae | æ | æ | æ |
lowercase c, cedilla | ç | ç | ç |
lowercase e, grave accent | è | è | è |
lowercase e, acute accent | é | é | é |
lowercase e, circumflex accent | ê | ê | ê |
lowercase e, umlaut | ë | ë | ë |
lowercase i, grave accent | ì | ì | ì |
lowercase i, acute accent | í | í | í |
lowercase i, circumflex accent | î | î | î |
lowercase i, umlaut | ï | ï | ï |
lowercase eth, Icelandic | ð | ð | ð |
lowercase n, tilde | ñ | ñ | ñ |
lowercase o, grave accent | ò | ò | ò |
lowercase o, acute accent | ó | ó | ó |
lowercase o, circumflex accent | ô | ô | ô |
lowercase o, tilde | õ | õ | õ |
lowercase o, umlaut | ö | ö | ö |
division sign | ÷ | ÷ | ÷ |
lowercase o, slash | ø | ø | ø |
lowercase u, grave accent | ù | ù | ù |
lowercase u, acute accent | ú | ú | ú |
lowercase u, circumflex accent | û | û | û |
lowercase u, umlaut | ü | ü | ü |
lowercase y, acute accent | ý | ý | ý |
lowercase thorn, Icelandic | þ | þ | þ |
lowercase y, umlaut | ÿ | ÿ | ÿ |
Alpha | Α | Α | |
alpha | α | α | |
Beta | Β | Β | |
beta | β | β | |
Gamma | Γ | Γ | |
gamma | γ | γ | |
Delta | Δ | Δ | |
delta | δ | δ | |
Epsilon | Ε | Ε | |
epsilon | ε | ε | |
Zeta | Ζ | Ζ | |
zeta | ζ | ζ | |
Eta | Η | Η | |
eta | η | η | |
Theta | Θ | Θ | |
theta | θ | θ | |
Iota | Ι | Ι | |
iota | ι | ι | |
Kappa | Κ | Κ | |
kappa | κ | κ | |
Lambda | Λ | Λ | |
lambda | λ | λ | |
Mu | Μ | Μ | |
mu | μ | μ | |
Nu | Ν | Ν | |
nu | ν | ν | |
Xi | Ξ | Ξ | |
xi | ξ | ξ | |
Omicron | Ο | Ο | |
omicron | ο | ο | |
Pi | Π | Π | |
pi | π | π | |
Rho | Ρ | Ρ | |
rho | ρ | ρ | |
Sigma | Σ | Σ | |
sigma | σ | σ | |
Tau | Τ | Τ | |
tau | τ | τ | |
Upsilon | Υ | Υ | |
upsilon | υ | υ | |
Phi | Φ | Φ | |
phi | φ | φ | |
Chi | Χ | Χ | |
chi | χ | χ | |
Psi | Ψ | Ψ | |
psi | ψ | ψ | |
Omega | Ω | Ω | |
omega | ω | ω | |
password dot | ● | ● | |
bullet | • | • |
ข้อมูลตาราง Special Characters in HTML จาก
http://www.degraeve.com/reference/specialcharacters.php