473,386 Members | 1,908 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,386 software developers and data experts.

inserting content into textarea

how can i use a javascript function to dynamically insert content into a textarea tag ?
is this possible? i've read tutorials on the doms and can't find any possibility.
thanks
Jul 18 '07 #1
9 1585
iam_clint
1,208 Expert 1GB
Example provided.
Expand|Select|Wrap|Line Numbers
  1. <textarea id="wow" name="wow"></textarea>
  2. <script>
  3. document.getElementById("wow").innerHTML = "This is the coolest site in the world!";
  4. </script>
  5.  
Jul 18 '07 #2
Example provided.
Expand|Select|Wrap|Line Numbers
  1. <textarea id="wow" name="wow"></textarea>
  2. <script>
  3. document.getElementById("wow").innerHTML = "This is the coolest site in the world!";
  4. </script>
  5.  

Or you may simplay write the below code

<script>
document.getElementById("wow").value = "This is the coolest site in the world!";
</script>
Jul 19 '07 #3
Or you may simply write the below code

<script>
document.getElementById("wow").value = "This is the coolest site in the world!";
</script>
This only works in IE6 and before.

In Firefox et al, you need
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. document.getElementById("wow").defaultValue = "This is the coolest site in the world!";
  3. </script>
  4.  
InnerHTML works on all browsers I have been able to test it on.

Does anyone know how to do this for IE7? None of the above methods work on my customer's site (and I can't run IE7 as I use win2K).
Jul 27 '07 #4
gits
5,390 Expert Mod 4TB
hi ...

i don't use IE ... i'm on a mac ;) ... but perhaps the following will work:

Expand|Select|Wrap|Line Numbers
  1. var text_node = document.createTextNode('text to append');
  2. var text_area = document.getElementById("wow");
  3.  
  4. text_area.appendChild(text_node);
  5.  
kind regards
Jul 27 '07 #5
hi ...

i don't use IE ... i'm on a mac ;) ... but perhaps the following will work:

Expand|Select|Wrap|Line Numbers
  1. var text_node = document.createTextNode('text to append');
  2. var text_area = document.getElementById("wow");
  3.  
  4. text_area.appendChild(text_node);
  5.  
kind regards
Good idea, but sadly it doesn't work either.

My code is currently
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function changeChassis() {
  3. var t = document.forms[0].chassistype.selectedIndex;
  4. var v = document.forms[0].chassistype.options[t].value;
  5. var res = 'junk';
  6. if(v == 'DAF LF55 220 4x2 Day cab 3750mm') 
  7.    res = 'DAF LF55 220 4x2 Day Cab 3750mm wheelbase 18 Tonnes G.V.W';
  8.  
  9. -- loads more if statements generated from database --
  10.  
  11. if(v == 'Volvo FM400 8x4 Globetrotter Cab 5100mm') 
  12.    res = 'Volvo FM400 8x4 Globetrotter Cab 5100mm wheelbase 32 Tonnes G.V.W';
  13. if(v == 'Volvo FM440 8x4 Sleeper Cab 5600mm') 
  14.    res = 'Volvo FM440 8x4 Sleeper Cab 5600mm wheelbase 32 Tonnes G.V.W';
  15. var fld = document.forms[0].chassisdescription;
  16. var node = document.createTextNode(res);
  17. fld.replaceChild(node,fld.childNodes[0]);
  18. }
  19. </script>
  20.  
chassisdescription is the textarea.
chassistype is the selection.
This is the onchange routine for chassistype.

Idea is to set the default to a fuller description of the chassis when one is selected - and permit later edits.

The code works fine in Safari, Firefox, IE6 on Win2K, but fails on the customer's site (Win Server 2003/ EI7).

I'm going bald trying to find out why.

Ian
Jul 27 '07 #6
gits
5,390 Expert Mod 4TB
hmmmm ... can you try to figure out what 'fld.childNodes[0]' is?

Expand|Select|Wrap|Line Numbers
  1. fld.replaceChild(node, fld.childNodes[0]);
  2.  
try an alert of nodeName or simply try to use appendChild ... my be replaceChild needs another reference for the node to be replaced? in case appendChild works we remove everything in the textarea and append the new one ;)

kind regards
Jul 27 '07 #7
Solved!

I have just got another user at the client site to test the code - it works for him!

So the problem is something to do with the set up on a single machine - and not IE7 at all.

The code in my previous post works in IE7.

Regards

Ian
Jul 27 '07 #8
gits
5,390 Expert Mod 4TB
glad to hear ... come back anytime when you have more questions ...

kind regards
Jul 27 '07 #9
iam_clint
1,208 Expert 1GB
Yes I was going to post that .innerHTML works on firefox, ie6, opera, ie7, and probably more but i haven't tested
Jul 27 '07 #10

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

Similar topics

1
by: M Wells | last post by:
Hi All, I've been checking the online javascript libraries for code that will show me how to insert characters at the current cursor point in a textarea form field to help me markup content I...
0
by: Krzysztof Fink-Finowicki via .NET 247 | last post by:
I have problem with TEXTAREA HTML tags in my Web application (MSIE 6.0). User fills-in content of TEXTAREA on HTML dialog window. After accepting, content of TEXTAREA from dialog window is...
2
by: Asad | last post by:
I have a form on a page that has several textareas, and textboxes inside a table (so the table containing the textboxes is also inside the FORM tag). I want to replace the textareas with simple...
3
by: M Wells | last post by:
Hi All, I'm wondering if anyone can point me to some JavaScript code I can drop into a page to respond to an attempt to click on specific links if content in textarea on a form has been changed...
3
by: autospanker | last post by:
Ladies and Gentleman, I have been having this problem that has been driving me insane. I have a website that when viewed in Firefox first, the content in the body area is pushed down. Then when...
1
by: spriguy21 | last post by:
Hey y'all, I am in need of some help...I am building a internal website for my department and I am using JavaScript to pull data from a local database since our corp office is being stingy and...
1
by: javediq143 | last post by:
Hi All, This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in...
4
by: liberty1 | last post by:
Hi everyone. I appreciate your effort at helping newbies like me. I have the following problems and will appreciate urgent help. PROBLEM NUMBER 1: Using PHP and MySQL, I am able to upload...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.