focus() onLoad

G

Gordan

Hi!

I have a very simple form and the idea is that when the page loads the focus
is set on the first textfield so that the user can start typing immediately
without pressing the tab key. so I did:

body onLoad="document.form.txtfield.focus()"

but id doesn't work, and no errors occurs. what gives?

many thanks
Gordan
 
T

The Plankmeister

body onLoad="document.form.txtfield.focus()"

Perhaps the form doesn't have the name "form" or the text box isn't named
"txtfield"? Only thing I can think of...

Perhaps give the text box a unique ID attribute... something like
id="text_focus" or whatever, then in the onload attribute do:

body onload="document.getElementById('text_focus').focus()"

That way you're accessing the element directly, rahter than navigating the
document tree.

HTH.

P.
 
W

Wim Poorten

The said:
Perhaps the form doesn't have the name "form" or the text box isn't
named "txtfield"? Only thing I can think of...

Or there are 2 forms with the name "form", or there are 2 text fields
with the name "txtfield".
 
N

nice.guy.nige

While the city slept said:
my spelling error :-(((

<g> Welcome to the fun and fulfilling world of debugging! ;-)

I once (erm... 15 years ago... eek!) spent nearly 3 days going through
several pages of COBOL code trying to find out why it wouldn't work...
eventually found I'd missed a full stop (period) from the end of one line.
Fixed that and it worked like a dream!

Cheers,
Nige

--
Nigel Moss.

Email address is not valid. (e-mail address removed). Take the dog out!
http://www.nigenet.org.uk | Boycott E$$O!! http://www.stopesso.com
"How strange the change from major to minor..."
 

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

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top