manipulating text in a textarea

G

Greg Scharlemann

Hey all,

I'm working on setting up a "Send this link to a Friend" page. The
page has a couple of inputs and a textarea. I have some default text
in the textarea that is populated at the time of page load. What I
would like to do is replace the "Dear Friend" in the textarea with the
name of the friend once it is entered in the input.

I don't really know where to start...

Thanks for the help, Greg

Some code:
--------------------------------------------------------------
<html>
<head>
<title></title>
<script type="text/javascript">
var message = "Dear Friend,\n\Check this out: url\n\nEnjoy...";
function populateTextarea() {
document.sendMessageForm.messageArea.value=message;
}
</script>
</title>
<body onLoad="javascript:populateTextarea();">
<form name="sendMessageForm">
Friends Name: &nbsp;
<input type="text name="friendsName" /><br/>
Your Name: &nbsp;
<input type="text" name="yourName" /><br/>
Message:&nbsp;
<textarea rows="10" cols="80" name="messageArea"></textarea>
<br/>
<input type="submit" name="Send Message" />
</body>
</html>
-----------------------------------------------------
 
J

johkar

Greg said:
Hey all,

I'm working on setting up a "Send this link to a Friend" page. The
page has a couple of inputs and a textarea. I have some default text
in the textarea that is populated at the time of page load. What I
would like to do is replace the "Dear Friend" in the textarea with the
name of the friend once it is entered in the input.

I don't really know where to start...

Thanks for the help, Greg

Some code:
--------------------------------------------------------------
<html>
<head>
<title></title>
<script type="text/javascript">
var message = "Dear Friend,\n\Check this out: url\n\nEnjoy...";
function populateTextarea() {
document.sendMessageForm.messageArea.value=message;
}
</script>
</title>
<body onLoad="javascript:populateTextarea();">
<form name="sendMessageForm">
Friends Name: &nbsp;
<input type="text name="friendsName" /><br/>
Your Name: &nbsp;
<input type="text" name="yourName" /><br/>
Message:&nbsp;
<textarea rows="10" cols="80" name="messageArea"></textarea>
<br/>
<input type="submit" name="Send Message" />
</body>
</html>
-----------------------------------------------------

There a many ways to accomplish this, here is one:

function addressMessage(elm,myForm){
if(elm.value != '')

myForm.elements['messageArea'].value=myForm.elements['messageArea'].value.replace(/Friend/,elm.value);
}

<input type="text" name="friendsName"
onblur="addressMessage(this,this.form)" />

Note you had a quote missing in type="text"
 
J

jack.murphy

You may want to look how we implemented Send-to-friend in
www.Deliverent.com

We found that the Send-to-friend is most effective when the sender
writes their own message instead of preparing a canned "sales-pitch"

Deliverent gives you the best of both world by automatically including
the HTML of the web page at the bottom of the email. This way the
website gets to make an indirect "sales pitch" and if the sender adds
their own message to the email, even better.

www.Deliverent.com is free to use on any site without restrictions and
has many more features then what I mentioned here.

Jack
 
G

Greg Scharlemann

johkar said:
There a many ways to accomplish this, here is one:

function addressMessage(elm,myForm){
if(elm.value != '')

myForm.elements['messageArea'].value=myForm.elements['messageArea'].value.replace(/Friend/,elm.value);
}

<input type="text" name="friendsName"
onblur="addressMessage(this,this.form)" />

I just attempted this using firefox and it doesn't seem to replace the
"Friend" text with the name typed into the box. Works well in IE... I
haven't tested it in any other browsers, but does anyone know what
about the above code firefox wouldn't like?

Thanks, Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top