Go Back   Velocity Reviews > Newsgroups > HTML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

HTML - How to select text in textbox

 
Thread Tools Search this Thread
Old 01-18-2005, 07:56 PM   #1
Default How to select text in textbox


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
  Reply With Quote
Old 01-18-2005, 08:06 PM   #2
Leif K-Brooks
 
Posts: n/a
Default Re: How to select text in textbox

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.
  Reply With Quote
Old 01-18-2005, 08:41 PM   #3
tshad
 
Posts: n/a
Default Re: How to select text in textbox

"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


  Reply With Quote
Old 01-18-2005, 09:28 PM   #4
Mitja
 
Posts: n/a
Default Re: How to select text in textbox

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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump