Help inserting text into existing innerHTML object??
I've built a WYSIWYG dhtml editor. Inserting links, images and all that stuff is pretty string forward using execCommand().
I'm looking for a way where as when a user clicks on a a © button my script will insert a character, such as a copyright symbol, at the current insertion point of an innerHTML object.
For instance the innerHTML is initally set to :
foo.innerHTML = 'Wrangler jeans are the best';
When a user places their cursor after the word Wrangler, then presses the © button, the script would change innerHTML to :
'Wrangler© jeans are the best';
Any ideas? I've been looking for a solution for hours.
Help is greatly appreciated!
Is all your editing done withing a textarea? or ???
Last edited by beetle; Aug 5, 2002 at 10:00.
This is done in Gecko browsers (NS6+, Mozilla, etc) via the selectionStart property of a textarea - it refers to the start of the selection (a caret could be considered a collapsed selection).
ta.value = ta.value.substring(0, ta.selectionStart) + 'something else' + ta.value.substr(ta.selectionStart);
Where ta is a reference to the textarea.
To do this in IE, you have to do something with its TextRange interface... webreference.com has a tutorial on it I think.
I'm still not very clear on how this is done...