Selecting contents of TEXTAREA by default

Discussion in 'HTML' started by Red_Indian, May 19, 2004.

  1. Red_Indian

    Red_Indian Guest

    Hi

    How do I have the contents of a TEXTAREA selected by default when I display it to the user
    (like the user doing Ctrl+A on that TEXTBOX immediately after opening the form).

    Please advise.
    Thanks in advance!
    RI
     
    Red_Indian, May 19, 2004
    #1
    1. Advertising

  2. Red_Indian

    \Mad\ Guest

    > How do I have the contents of a TEXTAREA selected by default when I
    display it to the user
    > (like the user doing Ctrl+A on that TEXTBOX immediately after opening the

    form).

    My apologies for replying. I'm unsure of both the
    correctness of my reply and the details, but maybe
    I can help.


    I believe, tho I could be wrong, that HTML does
    not allow you to choose the "focus" of the user's
    browser.


    But, if the user has enabled JavaScript, and
    has a reasonably recent browser
    (I think IE4, Netscape 4, or later, but I
    could be wrong; the tactic I'm thinking of
    needs JavaScript and DOM; it might be
    possible to do it with CSS, which I haven't
    learned enough about yet, and which, I think,
    requires an even newer browser)
    then there's an event, I think maybe it's called
    "OnLoad()", that can be used to trigger a
    Javascript function (which you would have to
    write) to move the browser's "focus" to the
    document element you want selected (focused
    on).


    I could have two separate things confused here.
    Maybe "focus" is where the "cursor" is, and
    "selection" is what is highlighted. They sort of
    go together, but are not exactly the same. The
    JavaScript might have to set both of them. I'm
    sorry, I don't remember the details, but I hope
    this gives you a direction to look in JavaScript..


    The "OnLoad" event (or whatever it is called;
    another thing you'll have to look for; it's either
    a JavaScript thing or a DOM thing, or maybe
    both), if I remember correctly, is triggered
    when the browser finishes downloading and
    is displaying the HTML page, before turning
    control over to the user.


    The DOM (Document Object Model; invented
    by Netscape to use with JavaScript, and so useful
    that it got spread and extended) is the system of
    naming parts of an HTML document as parts of
    a herarchical, tree-structured view of the HTML
    document, which provides names for JavaScript
    (and Java, and other scripting languages,
    and maybe CSS tho I could be mistaken
    about that)
    to use as "handles" so the JavaScript code can
    "target" parts of the HTML document (the page)
    to be affected or changed by the JavaScript.

    It's how the JavaScript code tells the browser
    _what_ to adjust on the page.


    The "event" (which may be part of the DOM,
    I forget exactly) , allows the JavaScript code
    to tell the browser _when_ to make an
    adjustment; in this case, OnLoad, after the HTML
    document (webpage) is downloaded and is
    being "rendered" (displayed).

    I think I remember there being events like OnLoad:, :
    OnMouseOver, OnKeyDown, OnKeyPress,
    OnKeyUp, OnFocus, OnBlur, etc. (and problems
    with overlapping events and events triggering
    other events, sometimes getting stuck in a loop).


    (Forgive me if you already know most of this.
    I couldn't tell from your brief problem description,
    and am trying to save the time that would be
    used in a back-and-forth question-and-answer
    session.)


    Does that help any?

    (And did I make any mistakes?)

    (i don't know the details. I did work with some of
    this, but not recently enough to have it fresh in my
    mind, and I never knew all of it.)


    Aloha,
    --
    Kenneth Kawamura
    Lansing, Michigan
    USA
     
    \Mad\, May 20, 2004
    #2
    1. Advertising

  3. Red_Indian

    Red_Indian Guest

    "Mad" wrote:

    > Does that help any?
    >


    Thanks a lot for that answer... especially for sparing the amount of time you did typing
    that mail!

    You were right... I looked around a bit and found a javascript function ".select" which
    did the trick:

    document.form.element.select() does it.

    Thanks once again...

    RI
     
    Red_Indian, May 25, 2004
    #3
  4. Red_Indian

    Red_Indian Guest

    "Mad" wrote:

    > Does that help any?
    >


    Thanks a lot for that answer... especially for sparing the amount of time you did typing
    that mail!

    You were right... I looked around a bit and found a javascript function ".select" which
    did the trick:

    document.form.element.select() does it.

    Thanks once again...

    RI
     
    Red_Indian, May 25, 2004
    #4
  5. Red_Indian

    Red_Indian Guest

    "Mad" wrote:

    > Does that help any?
    >


    Thanks a lot for that answer... especially for sparing the amount of time you did typing
    that mail!

    You were right... I looked around a bit and found a javascript function ".select" which
    did the trick:

    document.form.element.select() does it.

    Thanks once again...

    RI
     
    Red_Indian, May 25, 2004
    #5
  6. Red_Indian

    Red_Indian Guest

    "Mad" wrote:

    > Does that help any?
    >


    Thanks a lot for that answer... especially for sparing the amount of time you did typing
    that mail!

    You were right... I looked around a bit and found a javascript function ".select" which
    did the trick:

    document.form.element.select() does it.

    Thanks once again...

    RI
     
    Red_Indian, May 25, 2004
    #6
    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:
    367
    Ken Schaefer
    Sep 10, 2003
  2. Textarea Inside of a textarea

    , Feb 4, 2006, in forum: ASP General
    Replies:
    6
    Views:
    341
    Anthony Jones
    Feb 5, 2006
  3. gf
    Replies:
    0
    Views:
    85
  4. Sandman

    selecting portion of textarea/input

    Sandman, Feb 2, 2004, in forum: Javascript
    Replies:
    2
    Views:
    84
    Sandman
    Feb 3, 2004
  5. Replies:
    1
    Views:
    324
    Bart Van der Donck
    Jul 4, 2007
Loading...

Share This Page