473,395 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Add text to a textarea

I read a post about this before and I followed a link that should have helped but I'm still getting errors.

How to add text to a textarea

Here is a simple test of the concepts I learned from that link:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  6.  
  7. <head>
  8.    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  9.    <title>Textarea Test</title>
  10.  
  11.    <script type = "text/javascript">
  12.       <!--
  13.  
  14.       function addtext( txt ) {
  15.          document.myform.mytextarea.value += txt;
  16.  
  17.       }
  18.  
  19.       addtext( "I like cheese." );
  20.  
  21.  
  22.       // -->
  23.    </script>
  24. </head>
  25.  
  26. <body bgcolor="#ffffff">
  27.  
  28.    <form name = "myform" onSubmit = "return false;">
  29.  
  30.       <label>Textarea:</label><br />
  31.  
  32.       <textarea name = "mytextarea" rows = "20" cols = "50"></textarea>
  33.  
  34.  
  35.    </form>
  36.  
  37.  
  38. </body>
  39. </html>
IE gives me an error that says "Line 15 Char 7 Error: document.myform.mytextarea is null or not an object. Code: 0"

Any ideas as to what I'm doing wrong?

Swaine77
Jul 3 '06 #1
4 12383
I read a post about this before and I followed a link that should have helped but I'm still getting errors.

How to add text to a textarea

Here is a simple test of the concepts I learned from that link:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  6.  
  7. <head>
  8.    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  9.    <title>Textarea Test</title>
  10.  
  11.    <script type = "text/javascript">
  12.       <!--
  13.  
  14.       function addtext( txt ) {
  15.          document.myform.mytextarea.value += txt;
  16.  
  17.       }
  18.  
  19.       addtext( "I like cheese." );
  20.  
  21.  
  22.       // -->
  23.    </script>
  24. </head>
  25.  
  26. <body bgcolor="#ffffff">
  27.  
  28.    <form name = "myform" onSubmit = "return false;">
  29.  
  30.       <label>Textarea:</label><br />
  31.  
  32.       <textarea name = "mytextarea" rows = "20" cols = "50"></textarea>
  33.  
  34.  
  35.    </form>
  36.  
  37.  
  38. </body>
  39. </html>
IE gives me an error that says "Line 15 Char 7 Error: document.myform.mytextarea is null or not an object. Code: 0"

Any ideas as to what I'm doing wrong?

Swaine77


I also visited this website...

http://www.hscripts.com/tutorials/javascript/dom/textarea-events.php

and tried this code...


Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  6.  
  7. <head>
  8.    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  9.    <title></title>
  10.  
  11.    <script type = "text/javascript">
  12.       document.form1.textn.value = "testy";
  13.    </script>
  14.  
  15.  
  16. </head>
  17.  
  18. <body bgcolor="#ffffff">
  19.  
  20.    <form name=form1>
  21.    <textarea name=textn> testing text area </textarea>
  22.    </form>
  23.  
  24.  
  25.  
  26. </body>
  27. </html>

...and I'm getting the same error. What gives?
Jul 3 '06 #2
I also visited this website...

http://www.hscripts.com/tutorials/javascript/dom/textarea-events.php

and tried this code...


Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  6.  
  7. <head>
  8.    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  9.    <title></title>
  10.  
  11.    <script type = "text/javascript">
  12.       document.form1.textn.value = "testy";
  13.    </script>
  14.  
  15.  
  16. </head>
  17.  
  18. <body bgcolor="#ffffff">
  19.  
  20.    <form name=form1>
  21.    <textarea name=textn> testing text area </textarea>
  22.    </form>
  23.  
  24.  
  25.  
  26. </body>
  27. </html>

...and I'm getting the same error. What gives?

_______________________________________________

According to the W3C HTML documentation the "value" attribute is not defined for the textarea control, try the innerHTML attribute, as in:
document.form1.textn.innerHTML = "testy";
Oct 27 '06 #3
_______________________________________________

According to the W3C HTML documentation the "value" attribute is not defined for the textarea control, try the innerHTML attribute, as in:
document.form1.textn.innerHTML = "testy";

It's simple ! You loading document with all elements. But you load it in sequence. And in this time it's not done. Object form is not loaded !

Try thist:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>

<script type = "text/javascript">
function mojeFunkce()
{
document.form1.textn.value = "testy";
}
</script>


</head>

<body bgcolor="#ffffff" onload='mojeFunkce()'>

<form name=form1>
<textarea name=textn> testing text area </textarea>
</form>



</body>
</html>


and this:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>

<script type = "text/javascript">

document.form1.textn.value = "testy"; // this will not works !!!

</script>


</head>

<body bgcolor="#ffffff" onload='mojeFunkce()'>

<form name=form1>
<textarea name=textn> testing text area </textarea>
</form>



</body>
</html>
Oct 27 '06 #4
[quote=VelitelDruzstva]It's simple ! You loading document with all elements. But you load it in sequence. And in this time it's not done. Object form is not loaded !
]

Yes!, I didn't look further than the property for Textarea, missed the fact that it was being executed BEFORE the page was loaded!
Oct 28 '06 #5

Sign in to post your reply or Sign up for a free account.

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...
4
by: Newbie | last post by:
How would I modify this form to encode *all* the characters in the 'source' textarea to the '%xx' format & place result code into the 'output' textarea? (cross browser compatable) Any help is...
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
5
by: lawrence | last post by:
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: ...
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>
1
by: tranky | last post by:
Hola boys, i've a question for you! It's possible to highlight some text inside a textarea? (not all text, but a portion!) For example, i've this text inside a textarea. INSERISCI TESTO i...
4
by: devine | last post by:
Hi All, I am VERY new to Javascript. I have been provided with some code, which will enable me to hide/show a text area and change a submit button dependant on a check box. <!DOCTYPE html...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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...

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.