473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Auto-selecting all text in a field

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
4 2876
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
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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Manlio Perillo | last post by:
Hi. This post follows "does python have useless destructors". I'm not an expert, so I hope what I will write is meaningfull and clear. Actually in Python there is no possibility to write code...
1
by: Lew | last post by:
Hi all, I'm trying to create a page that has a user-selectable page auto-refresh option (IE 5.5). Essentially, it's a page that contains a checkbox, when the user checks the checkbox, I'd like...
9
by: Alan Mackenzie | last post by:
To all those who use (X)Emacs's CC Mode to edit C, C++, Java, Objective-C, Pike, AWK or IDL: To help direct the development of CC Mode, it would be useful to find out how people use the...
20
by: Vijay Kumar R. Zanvar | last post by:
Hello, Unlike register, auto keyword can not be used to declare formal parameter(s). Is there any specific reason for this? Kind regards, Vijay Kumar R. Zanvar
2
by: VB Programmer | last post by:
I created a page which I am using to prevent the user from hitting the BACK button. I'll call it my "Auto Jump" page. When it is called it basically auto-redirects to a page specified in the...
7
by: Brian | last post by:
hello, I am looking for a way to auto refresh a web page that I created, but also let the user choose to stop the auto refresh. I can not figure out how to stop the auto refresh. Any help would...
5
by: maya | last post by:
at work they decided to center divs thus: body {text-align:center} #content {width: 612px; text-align:left; margin: 0 auto 0 auto; } this works fine in IE & FF, EXCEPT in FF it doesn't work if...
22
by: nospam_news | last post by:
I currently get asked about my usage of "auto". What is it for? The keyword is clearly superflous here. In contrast to the huge majority of C/C++ developers I write definitions very explicitly...
2
by: Piotr K | last post by:
Hi, I've encountered a strange problem with Firefox which I don't have any idea how to resolve. To the point: I've <divelement with a style "height: auto" and I want to retrieve this value...
21
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.