views:

157

answers:

2

I have written a basic Greasemonkey script which passes an output out to a textarea, like this:

var obj = document.getElementById("comment").innerHTML = "\n" + "Note:" + "\n" + "\n" + output_string;

It works like a charm, if you change the value from the source, it will update the textarea. However, as soon as you write anything yourself inside the textarea and select a value, it will not overwrite what you written inside the textarea. And you need to refresh the page entirely to be able to use the function again. Why is that?

A: 

If you need your text area to always display the same text I suggest you attach blur event on it using your customized greasemonkey script. Blur event would do the same thing as it does now. The only change would be that textarea will be updated the moment cursor focuses off the textarea.

If that's what you were after, 'cause I didn't understand it quite clearly what are you trying to do.

Robert Koritnik
+3  A: 

The textarea's value attribute is set as soon as you type something into it. This overrides any innerHTML value.

You should be using the value attribute to set the contents of input elements like textarea.

Try this instead:

var obj = document.getElementById("comment").value = "\n" + "Note:" + "\n" + "\n" + output_string;
brianpeiris
Thank you, highly appreciated!
Belkin