471,594 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 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 12307
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

Post your reply

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

Similar topics

4 posts views Thread by Doug van Vianen | last post: by
5 posts views Thread by lawrence | last post: by
19 posts views Thread by dmiller23462 | last post: by
1 post views Thread by tranky | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

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.