473,238 Members | 1,796 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,238 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 12374
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: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.