Forum Moderators: open

Message Too Old, No Replies

Getting a tag to insert at cursor

Trying to get a tag to insert at cursor instead of at the end of the text

         

Jeffrey Levesque

4:08 am on Apr 11, 2008 (gmt 0)

10+ Year Member



Hello Everyone,

I know enough about Javascript and PHP to get myself into trouble. lol

Here's my problem:

I've got a simple script to insert personalization tags into a
textarea used for creating and saving an email.

I'd like to have the tags inserted wherever the user places their
cursor(in case they decide to add a tag later), instead of the tag
being inserted at the end of the text.

Here's what I have so far:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>
<title>Javascript test</title>
<script type='text/javascript'>
function inserttxt(id,symbol) {
var elem = document.getElementById(id)
var elemtext = elem.value

elem.value= elemtext + symbol
}
</script>
</head>
<body>
<textarea id='ta1'></textarea><br />
<a href='#' onclick='inserttxt("ta1",":)")'>:)</a><br />
<a href='#' onclick='inserttxt("ta1","%clickbank_button%")'>%clickbank_button%</a><br />
<a href='#' onclick='inserttxt("ta1","%register_page%")'>%register_page%</a>
<br /><br />
<textarea id='ta2'></textarea><br />
<a href='#' onclick='inserttxt("ta2",":)")'>:)</a><br />
<a href='#' onclick='inserttxt("ta2","%clickbank_button%")'>%clickbank_button%</a><br />
<a href='#' onclick='inserttxt("ta2","%register_page%")'>%register_page%</a>
</body>
<html>

==========================================

Any help will be GREATLY appreciated!

Warmest regards,

Jeff

daveVk

1:11 pm on Apr 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[alexking.org...]

Hope that helps, welcome to forum.

Jeffrey Levesque

10:59 am on Apr 12, 2008 (gmt 0)

10+ Year Member



Thanks a lot!

I can't believe I didn't find that at Alex's site earlier.

Jeff