How to select text in textbox

T

tshad

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

Leif K-Brooks

tshad said:
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.
 
T

tshad

Leif K-Brooks said:
tshad said:
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
 
M

Mitja

tshad said:
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.
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top