473,467 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Text box has no focus

JCO
I have a text box, on my form that I cant get the focus on. I'm using it as
shown:
<head>
<body onload=document.getPassword.txtPasswordName.focus( )>
</head>

Where
getPassword is the form &
txtPasswordName is the text box

Why is this? Anyone know a better way of doing this?
Jul 20 '05 #1
11 4446
" JCO" <J.********@verizon.net> wrote in message
news:UV*****************@nwrddc03.gnilink.net...
I have a text box, on my form that I cant get the focus on. I'm using it as shown:
<head>
<body onload=document.getPassword.txtPasswordName.focus( )>
</head>

Where
getPassword is the form &
txtPasswordName is the text box

Why is this? Anyone know a better way of doing this?

You probably can't use "onload=" as the form isn't loaded.

Remove "onload=" and add the following at the end of the page:

<script type="text/javascript">
document.getPassword.txtPasswordName.focus();
</script>
Jul 20 '05 #2
McKirahan wrote:
" JCO" <J.********@verizon.net> wrote in message
news:UV*****************@nwrddc03.gnilink.net...
I have a text box, on my form that I cant get the focus on. I'm using it


as
shown:
<head>
<body onload=document.getPassword.txtPasswordName.focus( )>
</head>

Where
getPassword is the form &
txtPasswordName is the text box

Why is this? Anyone know a better way of doing this?


You probably can't use "onload=" as the form isn't loaded.


Since onload events only happen after the document is loaded (thats what
its for), then the form is indeed loaded.
OP:
One major problem, and may/may not be part of the source of the problem,
is that the body tag goes after the </head> tag, the body is not part of
the head section. Although most browsers error correct soup code and
close the head when it encounters the body tag. Validate HTML before
complaining about javascript.

It also will depend on whether getPassword is the name or the id of the
form (It matters). Same for txtPasswordName.

Validate your code, after its valid, if it still doesn't set focus, post
the minimum code (or a URL) to the offending page.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #3
JCO
Yes the form name is getPassword and the text box name is txtPasswordName.
As shown:

<FORM NAME="getPassword" onSubmit="return GetUserInput()">
<p align="center">&nbsp;<INPUT TYPE="password" NAME="txtPasswordName"
VALUE="" SIZE=14>&nbsp;
<input type="reset" value="Clear" name="btnClear"></p>
<p align="center">Enter Password</p>

Base on this form, the onload is as shown:
<body onload=document.getPassword.txtPasswordName.focus( )>

Also, an important thing to note, the focus is set correctly when I preview
it in the browser. It does not work after the site is published.

Thanks again for the inputs!

"Randy Webb" <hi************@aol.com> wrote in message
news:DY********************@comcast.com...
McKirahan wrote:
" JCO" <J.********@verizon.net> wrote in message
news:UV*****************@nwrddc03.gnilink.net...
I have a text box, on my form that I cant get the focus on. I'm using
it
as
shown:
<head>
<body onload=document.getPassword.txtPasswordName.focus( )>
</head>

Where
getPassword is the form &
txtPasswordName is the text box

Why is this? Anyone know a better way of doing this?


You probably can't use "onload=" as the form isn't loaded.


Since onload events only happen after the document is loaded (thats what
its for), then the form is indeed loaded.
OP:
One major problem, and may/may not be part of the source of the problem,
is that the body tag goes after the </head> tag, the body is not part of
the head section. Although most browsers error correct soup code and
close the head when it encounters the body tag. Validate HTML before
complaining about javascript.

It also will depend on whether getPassword is the name or the id of the
form (It matters). Same for txtPasswordName.

Validate your code, after its valid, if it still doesn't set focus, post
the minimum code (or a URL) to the offending page.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #4
JCO
Nothing I do, puts the cursor in the text box. Seems strange.
I tried moving the onLoad to the bottom .. below the creation of the form.
It made no difference so I put it back at the beginning of the body.

Still not working!

"Randy Webb" <hi************@aol.com> wrote in message
news:DY********************@comcast.com...
McKirahan wrote:
" JCO" <J.********@verizon.net> wrote in message
news:UV*****************@nwrddc03.gnilink.net...
I have a text box, on my form that I cant get the focus on. I'm using
it
as
shown:
<head>
<body onload=document.getPassword.txtPasswordName.focus( )>
</head>

Where
getPassword is the form &
txtPasswordName is the text box

Why is this? Anyone know a better way of doing this?


You probably can't use "onload=" as the form isn't loaded.


Since onload events only happen after the document is loaded (thats what
its for), then the form is indeed loaded.
OP:
One major problem, and may/may not be part of the source of the problem,
is that the body tag goes after the </head> tag, the body is not part of
the head section. Although most browsers error correct soup code and
close the head when it encounters the body tag. Validate HTML before
complaining about javascript.

It also will depend on whether getPassword is the name or the id of the
form (It matters). Same for txtPasswordName.

Validate your code, after its valid, if it still doesn't set focus, post
the minimum code (or a URL) to the offending page.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #5
JCO wrote:
Nothing I do, puts the cursor in the text box. Seems strange.
I tried moving the onLoad to the bottom .. below the creation of the form.
It made no difference so I put it back at the beginning of the body.

Still not working!
Try the approach google uses (view source - relevant code shown).

<html>
<head>
<title>Google</title>
<script>
<!--
function sf(){document.f.q.focus();}
// -->
</script>
</head>
<body onLoad=sf()>
<form action="/search" name=f>
<input maxLength=256 size=55 name=q value="">
</body>
</html>

"Randy Webb" <hi************@aol.com> wrote in message
news:DY********************@comcast.com...
McKirahan wrote:
" JCO" <J.********@verizon.net> wrote in message
news:UV*****************@nwrddc03.gnilink.net.. .
I have a text box, on my form that I cant get the focus on. I'm using
it
as
shown:
<head>
<body onload=document.getPassword.txtPasswordName.focus( )>
</head>

Where
getPassword is the form &
txtPasswordName is the text box

Why is this? Anyone know a better way of doing this?

You probably can't use "onload=" as the form isn't loaded.


Since onload events only happen after the document is loaded (thats what
its for), then the form is indeed loaded.
OP:
One major problem, and may/may not be part of the source of the problem,
is that the body tag goes after the </head> tag, the body is not part of
the head section. Although most browsers error correct soup code and
close the head when it encounters the body tag. Validate HTML before
complaining about javascript.

It also will depend on whether getPassword is the name or the id of the
form (It matters). Same for txtPasswordName.

Validate your code, after its valid, if it still doesn't set focus, post
the minimum code (or a URL) to the offending page.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/


Jul 20 '05 #6
JCO
Yes, I tried it exactly as you explained and I also looked at the Google
site to read their code.
It is still not working.

Could it have anything to do with the type of text box?
Below is the exact code that I'm using:


<body>
...... other stuff

<!-- jco; This creates a form that contains a text field and 2-buttons to
validate users input -->
<FORM NAME="frmPassword" onEnter="return valForm()">
<!-- jco; Add two buttons and a text field -->
<p align="center">
<input type=password name="txtInput" size="28" onkeypress="onEnter();" ></p>
<p align="center">
<input type="button" value="Enter Password" name="btnEnter"
onclick="valForm();">&nbsp;&nbsp;
<input type="reset" value="Clear" name="btnClear"></p>
</form>

<!-- jco; Setfocus to text box so user can quickly sign in -->
<body onload=document.frmPassword.txtInput.focus()>

</body>

Note:
I just moved the onload to the bottom. Now it works, however, the cursor
keeps blinking. There is animaiton on the top frame. The cursor seems to
blink with the animation.

Should I move the line of code back to the top; Before the form?
Or should I manage the blinking ... somehow?


"mscir" <ms***@access4less.net> wrote in message
news:10*************@corp.supernews.com...
JCO wrote:
Nothing I do, puts the cursor in the text box. Seems strange.
I tried moving the onLoad to the bottom .. below the creation of the form. It made no difference so I put it back at the beginning of the body.

Still not working!


Try the approach google uses (view source - relevant code shown).

<html>
<head>
<title>Google</title>
<script>
<!--
function sf(){document.f.q.focus();}
// -->
</script>
</head>
<body onLoad=sf()>
<form action="/search" name=f>
<input maxLength=256 size=55 name=q value="">
</body>
</html>

"Randy Webb" <hi************@aol.com> wrote in message
news:DY********************@comcast.com...
McKirahan wrote:

" JCO" <J.********@verizon.net> wrote in message
news:UV*****************@nwrddc03.gnilink.net.. .
>I have a text box, on my form that I cant get the focus on. I'm using


it
as
>shown:
><head>
><body onload=document.getPassword.txtPasswordName.focus( )>
></head>
>
>Where
>getPassword is the form &
>txtPasswordName is the text box
>
>Why is this? Anyone know a better way of doing this?

You probably can't use "onload=" as the form isn't loaded.

Since onload events only happen after the document is loaded (thats what
its for), then the form is indeed loaded.
OP:
One major problem, and may/may not be part of the source of the problem,
is that the body tag goes after the </head> tag, the body is not part of
the head section. Although most browsers error correct soup code and
close the head when it encounters the body tag. Validate HTML before
complaining about javascript.

It also will depend on whether getPassword is the name or the id of the
form (It matters). Same for txtPasswordName.

Validate your code, after its valid, if it still doesn't set focus, post
the minimum code (or a URL) to the offending page.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #7
JCO wrote:
Yes, I tried it exactly as you explained and I also looked at the Google
site to read their code. It is still not working.

Could it have anything to do with the type of text box?
Below is the exact code that I'm using:

<FORM NAME="frmPassword" onEnter="return valForm()">
<p align="center">
<input type=password name="txtInput" size="28" onkeypress="onEnter();" ></p>
<p align="center">
<input type="button" value="Enter Password" name="btnEnter"
onclick="valForm();">&nbsp;&nbsp;
<input type="reset" value="Clear" name="btnClear"></p>
</form>
<body onload=document.frmPassword.txtInput.focus()>
...
</body>

Note:
I just moved the onload to the bottom. Now it works, however, the cursor
keeps blinking. There is animaiton on the top frame. The cursor seems to
blink with the animation.

Should I move the line of code back to the top; Before the form?
Or should I manage the blinking ... somehow?


2 questions:

- Do you have two <body> tags?
- Are you unhappy because the cursor blinks in the text box, or with the
RATE of blinking?

Not sure why this didn't work when you left the body tag where it
belongs, just following the <head> section:

<body onload=document.frmPassword.txtInput.focus()>

Maybe it has something to do with other code on the page.

How about you post your page somewhere where folks can view it? If you
don't have a site to publish it to you can easily get a free Geocities
web space after creating a Yahoo email account.

Mike

Jul 20 '05 #8
JCO
I only have one body tag such as:
<body>
....table stuff here
....form is loaded here, then
<body onload=document.frmPassword.txtInput.focus()>
</body>

The blinking is not consistent. It has the normal cursor blink, which is
okay, then every so often the blinking is interfered with by something else.
It is hard to explain. What is weird is that it all works fine when I
preview it.

I will let you know when I get it posted...thanks
"mscir" <ms***@access4less.net> wrote in message
news:10*************@corp.supernews.com...
JCO wrote:
Yes, I tried it exactly as you explained and I also looked at the Google
site to read their code. It is still not working.

Could it have anything to do with the type of text box?
Below is the exact code that I'm using:

<FORM NAME="frmPassword" onEnter="return valForm()">
<p align="center">
<input type=password name="txtInput" size="28" onkeypress="onEnter();"

</p>
<p align="center">
<input type="button" value="Enter Password" name="btnEnter"
onclick="valForm();">&nbsp;&nbsp;
<input type="reset" value="Clear" name="btnClear"></p>
</form>
<body onload=document.frmPassword.txtInput.focus()>
...
</body>

Note:
I just moved the onload to the bottom. Now it works, however, the cursor keeps blinking. There is animaiton on the top frame. The cursor seems to blink with the animation.

Should I move the line of code back to the top; Before the form?
Or should I manage the blinking ... somehow?


2 questions:

- Do you have two <body> tags?
- Are you unhappy because the cursor blinks in the text box, or with the
RATE of blinking?

Not sure why this didn't work when you left the body tag where it
belongs, just following the <head> section:

<body onload=document.frmPassword.txtInput.focus()>

Maybe it has something to do with other code on the page.

How about you post your page somewhere where folks can view it? If you
don't have a site to publish it to you can easily get a free Geocities
web space after creating a Yahoo email account.

Mike

Jul 20 '05 #9
JCO wrote:
I only have one body tag such as:
<body>
...table stuff here
...form is loaded here, then
<body onload=document.frmPassword.txtInput.focus()>
</body>

The blinking is not consistent. It has the normal cursor blink, which is
okay, then every so often the blinking is interfered with by something else.
It is hard to explain. What is weird is that it all works fine when I
preview it.

I will let you know when I get it posted...thanks


I'd recommend you remove the "<body onload..." line and use this approach:

http://www.projectseven.com/tutorial...rmfldfocus.htm

<form>
...all of the form code goes above this javascript...

<script type="text/javascript">
// set focus to form field
document.forms[0].MyFormFieldName.focus();
document.forms[0].MyFormFieldName.select();
</script>
</form>

Jul 20 '05 #10
mscir wrote:
JCO wrote:
I only have one body tag such as:
<body>
...table stuff here
...form is loaded here, then
<body onload=document.frmPassword.txtInput.focus()>
</body>

The blinking is not consistent. It has the normal cursor blink, which is
okay, then every so often the blinking is interfered with by something
else.
It is hard to explain. What is weird is that it all works fine when I
preview it.

I will let you know when I get it posted...thanks

I'd recommend you remove the "<body onload..." line and use this approach:

http://www.projectseven.com/tutorial...rmfldfocus.htm

<form>
...all of the form code goes above this javascript...

<script type="text/javascript">
// set focus to form field
document.forms[0].MyFormFieldName.focus();
document.forms[0].MyFormFieldName.select();
</script>
</form>


And if its not the first form on the page?

document.forms['formName'].elements['elementName'].focus();
document.forms['formName'].elements['elementName'].select();

Now it doesn't matter anymore.

but if it won't focus directly from the onload, set the onload to a
function and call it onload.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #11
JCO
This is working. Thanks!
Sorry we had to go back n forth so many times when it ended up to be 2-lines
of code.
Again, thanks.

----- Original Message -----
From: "Randy Webb" <hi************@aol.com>
Newsgroups: comp.lang.javascript
Sent: Saturday, February 14, 2004 11:35 AM
Subject: Re: Text box has no focus

"Randy Webb" <hi************@aol.com> wrote in message
news:YZ********************@comcast.com...
mscir wrote:
JCO wrote:
I only have one body tag such as:
<body>
...table stuff here
...form is loaded here, then
<body onload=document.frmPassword.txtInput.focus()>
</body>

The blinking is not consistent. It has the normal cursor blink, which is okay, then every so often the blinking is interfered with by something
else.
It is hard to explain. What is weird is that it all works fine when I
preview it.

I will let you know when I get it posted...thanks

I'd recommend you remove the "<body onload..." line and use this approach:
http://www.projectseven.com/tutorial...rmfldfocus.htm

<form>
...all of the form code goes above this javascript...

<script type="text/javascript">
// set focus to form field
document.forms[0].MyFormFieldName.focus();
document.forms[0].MyFormFieldName.select();
</script>
</form>


And if its not the first form on the page?

document.forms['formName'].elements['elementName'].focus();
document.forms['formName'].elements['elementName'].select();

Now it doesn't matter anymore.

but if it won't focus directly from the onload, set the onload to a
function and call it onload.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dong Ge | last post by:
I'm a new beginner of Python. I want to convet "Text 1" to "Text 2" below. How to do it? __ Dong Ge 2004.10.01 Text 1: .... Layer: Tv-Frame
3
by: Mark | last post by:
Hi, Im trying to validate a form, all the validating works apart from one field. This particular field must consist of the first 2 characters as letters, & the following 5 as numbers. And if it...
12
by: who be dat? | last post by:
I'm trying to make a webpage do the following: I want a user to be able to click on a given image (there will be more than one image). Upon clicking a given image, characters specific to that...
2
by: Peter Wright | last post by:
Hi all. Hopefully this should demonstrate the problem I'm having: http://flooble.net/~pete/focus-problem-demo/ (I'm testing it in Mozilla only, but I'm not sure if it's actually a...
3
by: VA | last post by:
t=document.getElementById('mytable') is a HTML table with some input fields in its cells Why doesnt t.getElementsByTagName('tr').firstChild.focus; put the focus on that text field? It...
3
by: Stefan Mueller | last post by:
I've an input box <input type = "text" name = "MyInput" value = ""> and a selection <select name = "MySelection" size = "1"> <option value = "1">Entry 1 <option value = "2">Entry 2 </select>...
1
by: dana1 | last post by:
I have a form with several combo boxes in the header used to determine the records that will be displayed on the form. When I tab or enter from the last combo box in the header, I want the focus to...
11
by: karen987 | last post by:
I have a web page which used to work fine until i added a rich text editor. the pages are in ASP and it is a news weblog, with a comments section where people click the headline of a comment and...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.