473,503 Members | 2,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2101
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
9299
by: Doug van Vianen | last post by:
Hi, I am working on an Applet which provides some mouse practice for new computer users in our local seniors' computer club. The applet contains several cards, in a card layout, which are...
4
11178
by: dekern | last post by:
I have been trying to set the default text value of a TextArea element for about a day now without any luck. Similar to the code used to set the Text field below I would like to use the returned...
1
3543
by: Volt | last post by:
is there any way to select and mark part of text in textarea by regular expression? i need to select the first string in textarea whitch is like xxxxx,xxx where x is any character
19
6854
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
1
3728
by: IkBenHet | last post by:
Hello, I found this script to create a simple rich text form (http://programmabilities.com/xml/index.php?id=17): <html> <head> <title>Rich Text Editor</title> </head> <body>
2
2068
by: Daniel Pitts | last post by:
Why doesn't this work? I create an object which is supposed to handle the selection in both IE and Firefox, but everytime I call getText() in firefox, I get the whole textarea, not just the...
8
2880
by: Floortje | last post by:
Hi, for the past few days now im trying to find some info on how to manipulate textarea's with javascript. Im trying to add content when a certain element is clicked or alter content if another is...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
7008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5594
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5022
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4688
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.