470,636 Members | 1,526 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,636 developers. It's quick & easy.

manipulating text in a textarea

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>
-----------------------------------------------------

Dec 18 '05 #1
4 1972
Greg Scharlemann wrote:
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"

Dec 18 '05 #2
Thanks Johkar...that works well...Greg

Dec 18 '05 #3
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

Greg Scharlemann wrote:
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>
-----------------------------------------------------


Dec 19 '05 #4
johkar wrote:
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

Dec 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Doug van Vianen | last post: by
19 posts views Thread by dmiller23462 | last post: by
2 posts views Thread by Daniel Pitts | last post: by
8 posts views Thread by Floortje | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.