fill a textarea

Discussion in 'Javascript' started by Werner, Oct 7, 2006.

  1. Werner

    Werner Guest

    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
    Werner, Oct 7, 2006
    #1
    1. Advertising

  2. Werner

    Guest

    Werner wrote:
    > 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.

    --
    http://creativeobjectworld.com - (cow)
    a free-form, text-based, browser-based, real-time, multi-user virtual
    world.
    , Oct 7, 2006
    #2
    1. Advertising

  3. Werner

    Ian Collins Guest

    wrote:
    > Werner wrote:
    >
    >>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.
    >

    I prefer setting textarea.value.

    --
    Ian Collins.
    Ian Collins, Oct 7, 2006
    #3
  4. Werner

    Guest

    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>

    Werner wrote:
    > 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
    , Oct 7, 2006
    #4
  5. wrote:

    > 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.

    >> 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.


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

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
    David Dorward, Oct 7, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Augustus
    Replies:
    1
    Views:
    333
    Ken Schaefer
    Sep 10, 2003
  2. Textarea Inside of a textarea

    , Feb 4, 2006, in forum: ASP General
    Replies:
    6
    Views:
    312
    Anthony Jones
    Feb 5, 2006
  3. Terry Todd
    Replies:
    0
    Views:
    153
    Terry Todd
    Sep 20, 2008
  4. David
    Replies:
    3
    Views:
    140
    Bagbourne
    Jul 5, 2003
  5. Replies:
    1
    Views:
    294
    Bart Van der Donck
    Jul 4, 2007
Loading...

Share This Page