Reputation: 2485
How can I add custom text to already written text in textarea using javascript??Thanks...
Upvotes: 7
Views: 31894
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
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