Click to See Complete Forum and Search --> : javascript inserting into a text field


ecwd
06-01-2003, 04:21 PM
I have a large textarea which a user can
edit a chunk of data from a database, I am currently using this code to
insert a link (just the html code) around a select piece of text:

function insertLink () {
if (!document.selection) return;
var str = document.selection.createRange().text;
if (!str) return;
var my_link = prompt('Enter URL:', 'http://');
if (my_link != null)
document.selection.createRange().text = '<a href="' + my_link + '">' + str + '</a>';
}

It works very well and when the data is displayed on the web page it
simply turns the html tag into a hyperlink (obviously). Now I want the
user to be able to insert an image tag somewhere in the textarea where
they have positioned the cursor (nb. they will not select a piece of text like
the above usage). Any ideas???