How to select text in textbox

Discussion in 'HTML' started by tshad, Jan 18, 2005.

  1. tshad

    tshad Guest

    I am already giving focus to my textbox using:

    <body onload="document.forms[0].firstName.focus();">

    Is there a way to select all the text, if there is any?

    Thanks,

    Tom.
     
    tshad, Jan 18, 2005
    #1
    1. Advertising

  2. tshad wrote:
    > I am already giving focus to my textbox using:
    >
    > <body onload="document.forms[0].firstName.focus();">
    >
    > Is there a way to select all the text, if there is any?


    Stop wanting that. If a user with a slow connection visits your site,
    they may start typing in the box before the page has fully loaded; then,
    when it's done loading, the text they've already typed will be selected.
    If they don't notice quickly enough, they will keep typing, erasing
    everything they've already written. Not very fun.
     
    Leif K-Brooks, Jan 18, 2005
    #2
    1. Advertising

  3. tshad

    tshad Guest

    "Leif K-Brooks" <> wrote in message
    news:...
    > tshad wrote:
    >> I am already giving focus to my textbox using:
    >>
    >> <body onload="document.forms[0].firstName.focus();">
    >>
    >> Is there a way to select all the text, if there is any?

    >
    > Stop wanting that. If a user with a slow connection visits your site, they
    > may start typing in the box before the page has fully loaded; then, when
    > it's done loading, the text they've already typed will be selected. If
    > they don't notice quickly enough, they will keep typing, erasing
    > everything they've already written. Not very fun.


    Good point.

    Thanks,

    Tom
     
    tshad, Jan 18, 2005
    #3
  4. tshad

    Mitja Guest

    On Tue, 18 Jan 2005 15:06:01 -0500, Leif K-Brooks <>
    wrote:

    > tshad wrote:
    >> I am already giving focus to my textbox using:
    >> <body onload="document.forms[0].firstName.focus();">
    >> Is there a way to select all the text, if there is any?


    > Stop wanting that. If a user with a slow connection visits your site,
    > they may start typing in the box before the page has fully loaded;


    What about doing it later? Like
    <textbox></textbox><script ...>selectEverythingInTheBoxAbove()</script>
    or even
    <textbox onfocus="this.selectAll()">

    That said, I must add I don't even know if JS code for selecting the
    contents exists. It very probably does, I'm just too lazy to check right
    now.

    --
    Mitja
     
    Mitja, Jan 18, 2005
    #4
    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. guy
    Replies:
    1
    Views:
    7,062
    John Timney \(Microsoft MVP\)
    Oct 6, 2004
  2. Replies:
    3
    Views:
    763
    George Ter-Saakov
    Feb 23, 2007
  3. agb

    writing two textbox's text in one textbox

    agb, Aug 26, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    181
    Ken Cox [Microsoft MVP]
    Aug 27, 2003
  4. ErwinP
    Replies:
    1
    Views:
    767
    ErwinP
    Aug 19, 2005
  5. palmiere
    Replies:
    1
    Views:
    431
    Erwin Moller
    Feb 9, 2004
Loading...

Share This Page