By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,254 Members | 1,713 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,254 IT Pros & Developers. It's quick & easy.

Auto-selecting all text in a field

P: n/a
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
Nov 28 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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()

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 28 '06 #2

P: n/a
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>
--

Nov 28 '06 #3

P: n/a
Paul J. Lucas said the following on 11/27/2006 10:43 PM:
Randy Webb <Hi************@aol.comwrote:
>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()

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.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 28 '06 #4

P: n/a

"Randy Webb" <Hi************@aol.comwrote in message
news:79********************@telcove.net...
Paul J. Lucas said the following on 11/27/2006 10:43 PM:
>Randy Webb <Hi************@aol.comwrote:
>>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()
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.
There's no better feeling than being a bit helpful in a terse and cryptic
way, then really pouncing when (surprise, surprise) the recipient didn't
quite get where you were coming from.

Well done. You're just so super.

A.

PS. If your time is so precious, why bother 'helping' people at all? (Oh,
yes -- there's the gratification of the pouncing thing. Sorry, I forgot.)
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/

Nov 28 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.