Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
138
rated 0 times [  144] [ 6]  / answers: 1 / hits: 19604  / 13 Years ago, sun, december 4, 2011, 12:00:00

Typically we run javascript code to set any value:



document.getElementById('id_name').value = ...;


But I have a page like this:



<div id=id_name>
<div class=class_name>
<textarea></textarea>
</div>
</div>


How to set a value of the textarea by javascript?



Thanks a lot for help!


More From » textarea

 Answers
28

You could do this, if your HTML is really that simple:



var textarea = document.getElementById('id_name').getElementsByTagName('textarea')[0];
textarea.value = hello world;


There's also a getElementsByClassName() in newer browsers that could be used to find the class_name <div> element, from which you'd do the getElementsByTagName() call.


[#88761] Friday, December 2, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kourtney

Total Points: 368
Total Questions: 103
Total Answers: 85

Location: Bonaire
Member since Sat, May 1, 2021
3 Years ago
kourtney questions
Sun, Oct 4, 20, 00:00, 4 Years ago
Tue, Oct 29, 19, 00:00, 5 Years ago
Thu, Apr 4, 19, 00:00, 5 Years ago
Fri, Mar 1, 19, 00:00, 5 Years ago
;