No problem there. I take it this will be used in a forum (or something
similar) to insert smilies or formatting code?
Exactly!! Good guess.
Ah. This is a problem. There is no standard way to get the current
location of the carat within a control in all browsers. Some browsers may
provide proprietary properties or methods to obtain this information (IE
does), but I expect most will not.
<snip>
This adds another problem. There is no intrinsic way to determine whether
a control has focus. You would have to track it yourself with focus/blur
events.
See the code I'm attaching below...
I'll mention now that writing code specific to IE is not my forte (I
despise the browser, so I spend little time with it). The code below does
essentially what you want, though.
<<snip>>
Thanks for the code. I'm pooped right now, had a really busy day. I'll try
it tomorrow or soon. I installed SP2 recently. Everything is running fine,
but it's been a while since I reinstalled everything. I think I'll do that
tomorrow for the heck of it. Anyway....
I'll post fragments of the code below which came from a reply page at
www.amdzone.com.
All the code was in the body of the HTML document. The little JS code I saw
in the head of the document didn't appear to have anything to do with this
but I could be wrong.
First, the actual function that handles this:
<script language="JavaS cript" type="text/javascript">
<!--
function emoticon(text) {
var txtarea = document.post.m essage;
text = ' ' + text + ' ';
if (txtarea.create TextRange && txtarea.caretPo s)
{
var caretPos = txtarea.caretPo s;
caretPos.text =
caretPos.text.c harAt(caretPos. text.length - 1) == ' ' ? caretPos.text + text
+ ' ' : caretPos.text + text;
txtarea.focus() ;
}
else
{
txtarea.value += text;
txtarea.focus() ;
}
}
//-->
</script>
Next, the code that displays the image and calls the function when the image
is clicked:
<a href="javascrip t:emoticon(':D' )"><img
src="./modules/PNphpBB2/images/smiles/icon_biggrin.gi f" border="0" alt="Very
Happy" title="Very Happy" width="15" height="15" /></a>
Here is the code for the text area. This appears to handle the focus and
other issues you referred to above.
<textarea class="post" id="message" name="message" rows="15" cols="35"
style="width:45 0px;height:202p x" tabindex="3" onselect="store Caret(this);"
onclick="storeC aret(this);" onkeyup="storeC aret(this);"></textarea>
The error I get occurs when I click an image and the function is called. It
appears the very first line in the function causes the problem. If I
understand this line correctly, it's try to pull all the text out of the
text area and store the text in a variable. However, the error message I
got (don't recall the exact wording) seemed to indicated it couldn't find
the object (the textarea) to pull the text from or the object doesn't exist.
Again, I'll give your code a shot. However, you sound like you aren't
confident it will do what I'll need it to do. Any idea why this code isn't
working in my webpage?
Thanks again!!
Chris Smith