halocursed
halocursed

Reputation: 2485

Add text to text area using javascript

How can I add custom text to already written text in textarea using javascript??Thanks...

Upvotes: 7

Views: 31894

Answers (3)

karim79
karim79

Reputation: 342625

function addText(elId,text) {
    document.getElementById(elId).value += text;
}

or:

function addText(elId,text) {
    var obj = document.getElementById(elId);
    var txt = document.createTextNode(text);
    obj.appendChild(txt);
}

Upvotes: 18

timdev
timdev

Reputation: 62874

Grab the existing text in the textarea (the element's .value)

Combine your existing text (append, prepend, insert, or whatever you need)

Write the result back to the textarea.

Tah-dah!

Upvotes: 0

Eli Grey
Eli Grey

Reputation: 35830

myTextarea.value += "text to add to the textarea"

Upvotes: 2

Related Questions