I am sure this is helpful to some of you. I was searching for something like this in TEK-TIPS and got the impression that it was impossible.
Try it out, its great!
Remco
I got the source from:
Author: VDSLUIS.NET
Language: JAVASCRIPT
<HTML>
<HEAD>
<TITLE>Example</TITLE>
<SCRIPT>
function storeCaret (textEl)
{
if (textEl.createTextRange) textEl.caretPos =
document.selection.createRange().duplicate();
}
function insertAtCaret (textEl, text)
{
if (textEl.createTextRange && textEl.caretPos)
{
var caretPos = textEl.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
}
else
textEl.value = text;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<TEXTAREA NAME="content" COLS=40 ROWS=6
ONSELECT="storeCaret(this);"
ONCLICK="storeCaret(this);"
ONKEYUP="storeCaret(this);">Some example text</textarea>
<INPUT TYPE="button" STYLE="font-family:courier;" VALUE="-COOL-"
ONCLICK="insertAtCaret(this.form.content,'-COOL-');">
</FORM>
</BODY>
</HTML>
Try it out, its great!
Remco
I got the source from:
Author: VDSLUIS.NET
Language: JAVASCRIPT
<HTML>
<HEAD>
<TITLE>Example</TITLE>
<SCRIPT>
function storeCaret (textEl)
{
if (textEl.createTextRange) textEl.caretPos =
document.selection.createRange().duplicate();
}
function insertAtCaret (textEl, text)
{
if (textEl.createTextRange && textEl.caretPos)
{
var caretPos = textEl.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
}
else
textEl.value = text;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<TEXTAREA NAME="content" COLS=40 ROWS=6
ONSELECT="storeCaret(this);"
ONCLICK="storeCaret(this);"
ONKEYUP="storeCaret(this);">Some example text</textarea>
<INPUT TYPE="button" STYLE="font-family:courier;" VALUE="-COOL-"
ONCLICK="insertAtCaret(this.form.content,'-COOL-');">
</FORM>
</BODY>
</HTML>