472,962 Members | 2,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,962 software developers and data experts.

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 2071
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
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
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
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
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
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
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
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
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.