7

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

3 Answers 3

18
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);
}
Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

what is myTextarea in this case?
0

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!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.