/    Sign up×
Community /Pin to ProfileBookmark

create new line in <textarea>

i have a written a code which creates an output into a textarea, the only problem is that i do not know how to write new lines in textareas using javascript

n does not work
<br> does not work
&#13; does not work

… im running out of ideas,

any help?

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@fredmvApr 14.2004 — The newline meta character (i.e., [font=courier]n[/font]) does indeed work.&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"&gt;
&lt;head&gt;
&lt;title&gt;untitled&lt;/title&gt;
&lt;meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" /&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action="#"&gt;
&lt;div&gt;
&lt;textarea rows="10" cols="50"&gt;&lt;/textarea&gt;
&lt;a href="#" onclick="elements[0].value += 'foon';"&gt;Add another line.&lt;/a&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@benjaminauthorApr 14.2004 — i had given the textarea an id and was using its innerHTML, that was why it was not working.

thankyou for your quick reply
Copy linkTweet thisAlerts:
@JayDieApr 14.2004 — [i]Originally posted by benjamin [/i]

[B]i had given the textarea an id and was using its innerHTML, that was why it was not working.



thankyou for your quick reply [/B]
[/QUOTE]


No, that was not the problem. You can give the Textarea an ID, no problem. But if you wanted to use innerHTML, use innerText instead.

[code=php]
<html>
<head>
</head>
<body>
<textarea id="tekst" rows="10" cols="50">test...</textarea>
<hr />
<a href="#" onClick="javascript: document.getElementById('tekst').value += 'TESTntestnntest'">Click to add...</a>
</body>
</html>
[/code]


I red something about: 'don't use innerHTML, etc, but use nodeChild ed instead'. Can somebody tell me more about this? Why and explain so I can see 'the picture' ?

JayDie
Copy linkTweet thisAlerts:
@fredmvApr 14.2004 — [i]Originally posted by JayDie [/i]

[B]I red something about: 'don't use innerHTML, etc, but use nodeChild ed instead'. Can somebody tell me more about this? Why and explain so I can see 'the picture'[/B][/QUOTE]
http://forums.webdeveloper.com/showthread.php?s=&threadid=32137
Copy linkTweet thisAlerts:
@steelersfan88Apr 14.2004 — innerHTML is simply not DOM, as .[child].nodeValue is
×

Success!

Help @benjamin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...