Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

caretPos always returning undefined

Hi,

Can someone tell me why caretPos always return "undefined"? It's a function to add smileys to my webpage and it's almost the same than many forums on the internet. It does the same error with IE 6 and Firefox.

Here's my function:

function addSmiley(text) {
var tArea = document.post.message;
text = ' ' + text + ' ';
if (tArea.createTextRange && tArea.caretPos) {
var caretPos = tArea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
txtarea.focus();
} else {
tArea.value += text;
tArea.focus();
}
}

Thanks for any help!

Steph
[749 byte] By [steph2004] at [2007-11-11 7:01:23]