473,726 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

once again, how to add text to a textarea

How to add text to a textarea using javascript? Apparently this is a
popular question, because when I run the search on google, there are a
lot of returns:

http://groups.google.com/groups?hl=e...ang.javascript
However, all of the examples seem case specific, rather than generic.
I'm new to Javascript, so it is not so easy for me to take a specific
example and make it abstract enough to work as a generic function.

This example was given of how to add a newline to each line in a
textarea. I can imagine how to make this generic, but the example is
from 1999 and I'm wondering if this is still a valid way to go.

document.form1. textarea.value += document.form1. text.value + '\n';
Or, assuming I've a variable called myNewText, would this work better?
Would this work on all the major browsers?

document.getEle mentById(myText area).value .= myNewText;
I also saw this example from 2001. If I change "sendformre ply" to the
name of my textarea (or is it the id of the textarea?) then could I
make this work for me?

function addto_text(smil ey_txt) {
document.sendfo rmreply.body.va lue += ' ' + smiley_txt + ' ';
document.sendfo rmreply.body.fo cus();
}
Any help much appreciated. I'm sure I'll stop asking stupid questions
in about 2 months.
Jul 23 '05 #1
5 3020
lawrence wrote:
How to add text to a textarea using javascript? Apparently this is a
popular question, because when I run the search on google, there are a
lot of returns:

http://groups.google.com/groups?hl=e...ang.javascript
However, all of the examples seem case specific, rather than generic.
I'm new to Javascript, so it is not so easy for me to take a specific
example and make it abstract enough to work as a generic function.

This example was given of how to add a newline to each line in a
textarea. I can imagine how to make this generic, but the example is
from 1999 and I'm wondering if this is still a valid way to go.

document.form1. textarea.value += document.form1. text.value + '\n';
Did you test it?

Or, assuming I've a variable called myNewText, would this work better?
Would this work on all the major browsers?

document.getEle mentById(myText area).value .= myNewText;
Again, test it. But replace the PHP-type method of concatenation with +=

I also saw this example from 2001. If I change "sendformre ply" to the
name of my textarea (or is it the id of the textarea?) then could I
make this work for me?

function addto_text(smil ey_txt) {
document.sendfo rmreply.body.va lue += ' ' + smiley_txt + ' ';
document.sendfo rmreply.body.fo cus();
}


Again, test it :)

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #2
Lee
lawrence said:
This example was given of how to add a newline to each line in a
textarea. I can imagine how to make this generic, but the example is
from 1999 and I'm wondering if this is still a valid way to go.

document.form1 .textarea.value += document.form1. text.value + '\n';
Yes. That's still the most reliable way to add text to the
end of a textarea, where "form1" is the NAME attribute of
the form, and "textarea" is the NAME attribute of the textarea.

Or, assuming I've a variable called myNewText, would this work better?
Would this work on all the major browsers?

document.getEl ementById(myTex tarea).value .= myNewText;
You mean += not .=
That will work if "myTextarea " is the ID attribute (not the NAME)
of the textarea AND if the browser is modern enough to support
getElementById( ).

I also saw this example from 2001. If I change "sendformre ply" to the
name of my textarea (or is it the id of the textarea?) then could I
make this work for me?

function addto_text(smil ey_txt) {
document.sendfo rmreply.body.va lue += ' ' + smiley_txt + ' ';
document.sendfo rmreply.body.fo cus();
}


In that example, "sendformre ply" is the name of the form,
and "body" is the name of the textarea.

Jul 23 '05 #3
Randy Webb <Hi************ @aol.com> wrote in message news:<WI******* *************@c omcast.com>...
lawrence wrote:
How to add text to a textarea using javascript? Apparently this is a
popular question, because when I run the search on google, there are a
lot of returns:

http://groups.google.com/groups?hl=e...ang.javascript
However, all of the examples seem case specific, rather than generic.
I'm new to Javascript, so it is not so easy for me to take a specific
example and make it abstract enough to work as a generic function.

This example was given of how to add a newline to each line in a
textarea. I can imagine how to make this generic, but the example is
from 1999 and I'm wondering if this is still a valid way to go.

document.form1. textarea.value += document.form1. text.value + '\n';


Did you test it?


Your answer could offer some details. What is the best way to test it?
How does one debug in Javascript?
Jul 23 '05 #4
lawrence wrote:
Randy Webb wrote:
Did you test it?


What is the best way to test it?
How does one debug in Javascript?


By using a browser with a script debugger. I recommend Mozilla Firefox.

http://www.mozilla.org/products/firefox/

--
Ben M.
Jul 23 '05 #5
Lee
lawrence said:

Randy Webb <Hi************ @aol.com> wrote in message
news:<WI****** **************@ comcast.com>...
lawrence wrote:
> How to add text to a textarea using javascript? Apparently this is a
> popular question, because when I run the search on google, there are a
> lot of returns:
>

http://groups.google.com/groups?hl=e...ang.javascript
>
>
> However, all of the examples seem case specific, rather than generic.
> I'm new to Javascript, so it is not so easy for me to take a specific
> example and make it abstract enough to work as a generic function.
>
> This example was given of how to add a newline to each line in a
> textarea. I can imagine how to make this generic, but the example is
> from 1999 and I'm wondering if this is still a valid way to go.
>
> document.form1. textarea.value += document.form1. text.value + '\n';


Did you test it?


Your answer could offer some details. What is the best way to test it?
How does one debug in Javascript?


You test it by creating a simple test case, as below.
I've also added a couple of alert()'s to show a simple
way to debug code:
<html>
<head>
<title>Testin g</title>
<script type="text/javascript">
function appendText(fiel d,str) {
alert("appendin g: \""+str+"\"" );
field.value += str;
alert("new value is: \""+field.value +"\"");
}
</script>
</head>
<body>
<form name="form1">
<input name="newText">
<input type="button"
value="append text"
onclick="append Text(this.form. myArea,this.for m.newText.value )">
<input type="button"
value="newline"
onclick="append Text(this.form. myArea,'\n')">
<br>
<textarea name="myArea" cols="40" rows="10">Initi al value.</textarea>
</form>
</body>
</html>

Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
9325
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 displayed to the user one after the other as needed to present some particular mouse operation. This all works fine. One card (card 4 below) includes a textarea and a button. What I wish to do is have the user use the mouse to select some text from the...
1
3571
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
6927
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 JavaScript in this code from a couple different sites but I'm not 100% sure what each line is doing...This is the ASP code that I'm using for the page....Take a look at the JavaScript code and please let me know what each line is doing....I have been...
1
3766
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
1465
by: Dung Ping | last post by:
I posted a similar question quite a while ago, but didn't get positive answer. Beofore turning to other approaches, I would like to check again. Following is what I like to do: Chinese is a tone language. There are four tones that are referred to as Tone 1 through Tone 4. The language is usually written with an ideographic script of characters. But there is a less-used alphabetic writing that consists of the 26 letters for English and...
2
2096
by: Rhys.Mataira | last post by:
My code will not show up anything at all on the screen can someone guide me why this would be? <?php $pagetitle="Login"; If (!$_POST) or (!$_POST) { echo" <head></head> <style type=\”text/css\”> <!--
5
2724
by: Chris | last post by:
I have a meetings section I'm developing on our intranet. Using PHP/MySQL. Meeting info and Meeting docs reside on 2 related tables in the db. Users may want to upload anywhere from 1 to 10 or more documents to share/use during a meeting presentation. What would be the most efficient way to approach this? This is the logic I'm currently considering: Page 1: Meeting Information input with link to a document upload page (this page...
13
2010
by: destiny007 | last post by:
Hi, can any one help me to create the pop up only once. on clicking the text box <html> <head> <script type="text/javascript"> function abc() { var wind1=null;
0
8890
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9402
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9259
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9120
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8101
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3228
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 we have to send another system
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.