views:

28

answers:

3

hey guys, wonder what i'm doing wrong?

javascript:document.getElementsByTagName('textarea').innerHTML='inserted';

i want to create a bookmarklet to insert simple text to a textarea on a given webpage.

regards matt

A: 

Use the value:

javascript:document.getElementsByTagName('textarea').value = 'inserted';
Sarfraz
whenever i fire the piece of code, the entire website get's blank and inserted is printed on to it.
A: 

In jQuery you have to use if this way:

for single element -> $('#element_id').html('your html here')
for all text areas -> $('textarea').val('your html here')

I have to confess that I`m not sure why it works this way but it works. And use rameworks, they will save you time and nerves.

Ilian Iliev
A: 

Use the value property rather than innerHTML and make sure your code evaluates to undefined, which you can do by wrapping it in a function with no return statement. If you don't do this, the contents of the page will be replaced with whatever your code evaluates to (in this case, the string 'inserted').

javascript:(function() {document.getElementsByTagName('textarea').value = 'inserted';})();
Tim Down