If you can use jQuery, and I highly recommend you do, you would simply do
$('#myTextArea').val('');
Otherwise, it is browser dependent. Assuming you have
var myTextArea = document.getElementById('myTextArea');
In most browsers you do
myTextArea.innerHTML = '';
But in Firefox, you do
myTextArea.innerText = '';
Figuring out what browser the user is using is left as an exercise for the reader. Unless you use jQuery, of course ;)
Edit: I take that back. Looks like support for .innerHTML on textarea's has improved. I tested in Chrome, Firefox and Internet Explorer, all of them cleared the textarea correctly.
Edit 2: And I just checked, if you use .val('') in jQuery, it just sets the .value property for textarea's. So .value should be fine.
Like this:
or like this in jQuery:
Where you have
For all the downvoters and non-believers:
Here's the MSDN reference
Here's the MDN reference
If its Jquery ..
or
http://www.hscripts.com/tutorials/javascript/dom/textarea-events.php
If you can use jQuery, and I highly recommend you do, you would simply do
Otherwise, it is browser dependent. Assuming you have
In most browsers you do
But in Firefox, you do
Figuring out what browser the user is using is left as an exercise for the reader. Unless you use jQuery, of course ;)
Edit: I take that back. Looks like support for .innerHTML on textarea's has improved. I tested in Chrome, Firefox and Internet Explorer, all of them cleared the textarea correctly.
Edit 2: And I just checked, if you use .val('') in jQuery, it just sets the .value property for textarea's. So .value should be fine.
Although many correct answers have already been given, the classical (read non-DOM) approach would be like this:
where in the HTML your textarea is nested somewhere in a form like this:
And as it happens, that would work with Netscape Navigator 4 and Internet Explorer 3 too. And, not unimportant, Internet Explorer on mobile devices.
put the textarea to a form, naming them, and just use the dom objects easily, like this: