How to add text to a textarea using javascript? Apparently this is a
popular question, because when I run the search on google, there are a
lot of returns:
http://groups.google.com/groups?hl=e...ang.javascript
However, all of the examples seem case specific, rather than generic.
I'm new to Javascript, so it is not so easy for me to take a specific
example and make it abstract enough to work as a generic function.
This example was given of how to add a newline to each line in a
textarea. I can imagine how to make this generic, but the example is
from 1999 and I'm wondering if this is still a valid way to go.
document.form1.textarea.value += document.form1.text.value + '\n';
Or, assuming I've a variable called myNewText, would this work better?
Would this work on all the major browsers?
document.getElementById(myTextarea).value .= myNewText;
I also saw this example from 2001. If I change "sendformreply" to the
name of my textarea (or is it the id of the textarea?) then could I
make this work for me?
function addto_text(smiley_txt) {
document.sendformreply.body.value += ' ' + smiley_txt + ' ';
document.sendformreply.body.focus();
}
Any help much appreciated. I'm sure I'll stop asking stupid questions
in about 2 months.