fill a textarea

W

Werner

Hello,
how can fill automatically a textarea when opening a webpage.
I want to do this by a function that has been raised in js file.

thx
 
W

wooolis

Werner said:
Hello,
how can fill automatically a textarea when opening a webpage.
I want to do this by a function that has been raised in js file.

I belive the innerHTML is the way to get stuff into a textarea tag.
 
A

agapeton

You need to use the 'value' attribute on the textarea (not innerHTML).
Furthermore, you need to access it AFTER the page has loaded, not
before. So, you need to put it in a function that is executed after
the page has loaded. So, the following won't work at all...


<script type="text/javascript">
<!--
document.getElementById('taMyText').value = 'asdfsdf';
// -->
</script>

This is what you want...

<script type="text/javascript">
<!--
window.onload = function(evt) {
document.getElementById('taMyText').value = 'asdfsdf';
}
// -->
</script>

Given this xhtml:
<textarea id="taMyText"></textarea>
 
D

David Dorward

You need to use the 'value' attribute on the textarea (not innerHTML).

Property, not attribute.
Furthermore, you need to access it AFTER the page has loaded, not
before.

You don't need to wait for the entire page to load, just for the textarea to
be created.
This is what you want...

<script type="text/javascript">
<!--

You don't want HTML comments in your script elements. They only serve to
protect browsers of the Pre-Netscape 3 generations (and they have much
bigger problems then rendering JS as text) and are actively harmful in
XHTML.
Given this xhtml:
<textarea id="taMyText"></textarea>

The rows and cols attributes are not optional.

Why are you responding and /then/ quoting what you are responding to? Its
backwards and makes no sense.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top