Auto-selecting all text in a field

P

Paul J. Lucas

I have a simple form that contains an INPUT element that has an
initial value.

<form name="Form">
<input name="Number" type="text" value="Hello">
</form>

When the form loads, I want all of the text in the field to be
automatically selected. How can I do this?

Doing a:

document.Form.Number.select();

selects the INPUT element itself, not the text inside of it.

- Paul
 
R

Randy Webb

Paul J. Lucas said the following on 11/27/2006 9:40 PM:
have a simple form that contains an INPUT element that has an
initial value.
<form name="Form">
<input name="Number" type="text" value="Hello">
</form>
When the form loads, I want all of the text in the field to be
automatically selected. How can I do this?

document.Form.Number.focus()
 
P

Paul J. Lucas

Randy Webb said:
Paul J. Lucas said the following on 11/27/2006 9:40 PM:

document.Form.Number.focus()

No, that gives focus to the INPUT element. It does not select
the text inside. Try it yourself.

- Paul
 
L

Lee

Paul J. Lucas said:
I have a simple form that contains an INPUT element that has an
initial value.

<form name="Form">
<input name="Number" type="text" value="Hello">
</form>

When the form loads, I want all of the text in the field to be
automatically selected. How can I do this?

Doing a:

document.Form.Number.select();

selects the INPUT element itself, not the text inside of it.

What does it mean to select the element itself? How does it indicate
that if it's not selecting the text?

This simple example selects the text "Hello" in Firefox and IE.
What does it do in your browser?

<html>
<body>
<form name="Form">
<input name="Number" value="Hello">
<input name="Other" value="World">
<br>
<input type="button" value="select" onclick="document.Form.Number.select()">
</form>
</body>
</html>


--
 
R

Randy Webb

Paul J. Lucas said the following on 11/27/2006 10:43 PM:
No, that gives focus to the INPUT element.
Correct.

It does not select the text inside.

Correct again.

Combine the two and test it again. Do you need me to come code it,
upload it, and get paid for it as well? While I am there, maybe I can
teach you how not to indent with tabs.
 

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,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top