...

View Full Version : how to insert text in a text area depending on the cursor position



glb
07-10-2002, 02:35 PM
I hope the subject is clear...
I would like to insert a selected item value of a combo at the position where the focus is in a textarea (so, not at the end) that already contains text.

jkd
07-10-2002, 05:48 PM
Say you have insertValue equal to the string you want to insert.

In recent builds of Mozilla, you can go like:

refToTextArea.value = refToTextArea.value.substr(0, refToTextArea.selectionStart) + insertValue + refToTextArea.value.substring(refToTextArea.selectionStart);

Not sure exactly the methods to do it in IE, but it involves the TextRange() object... somebody else here should know how.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum