[web] Inserting objects into textarea's

Started by
2 comments, last by GameDev.net 18 years, 8 months ago
I've searched around for a couple of hours, and I can't find what I need, or it is way too complex. How can I insert a specific tag at the cursors position by clicking a button?

<html>
<script language="JavaScript" type="text/JavaScript">
function sendText(e, text)
{e.value=e.value + text;}
</script>
<body>
<img name="image" width="300" height="200" onClick="sendText(document.form1.taupdate, '<font color=red>')">
<br>
<form name="form1" method="post" action="">
<textarea name="taupdate" cols="30" id="taupdate"></textarea>
</form><
</body></html>

This adds text to the end of it, but how can I add text to wherever the cursor is?
Advertisement
I have personally never seen it done. Looks like your users are just going to have to cut and paste the tags to get them where they want them.
It's possible. Take a look at the &#106avascript in the "new topic/post reply" form on any phpBB powered website (like, for example, phpBB's own site).

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

You can actually insert text where the cursor is. Visit http://www.alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-&#106avascript/

This topic is closed to new replies.

Advertisement