[Javascript] onLoad Focus

Paul Novitski paul at dandemutande.org
Thu Apr 1 13:49:47 CST 2004


John,

I suggest you use the HTML attribute tabindex; see:
http://www.w3.org/TR/1998/REC-html40-19980424/interact/forms.html#h-17.11

I would steer you away from MERELY setting focus on an input field in the 
body onLoad event.  If your page takes a few seconds to load, say because 
it contains heavy images and/or your user is on dial-up, the HTML input 
fields on the page will resolve before onLoad completes.  If your user is 
already happily typing away in another input field when onLoad completes, 
the editing cursor will suddenly jump to the field you want them to get to 
first.  This is technically known as a User-Unfriendly Event.

onLoad:focus() is a pet peeve of mine: my online bank's image-heavy logon 
page does this, and I have to log in carefully or I'll end up typing the 
last half of my password into the user Id field.  Grr!

If you're going to go this route, please check to make sure the user hasn't 
already placed the focus somewhere else before setting focus in 
onLoad().  Or render all your input fields disabled, and enable them in 
your onLoad event.  Or something!

Fervently,
Paul


At 10:51 AM 4/1/2004, John Cross wrote:

>Hi All,
>I am writing a web page where I build a list of submitted values, but as 
>my list grows my input field gets pushed off the bottom of the visible 
>page.  So I want to use the focus function to put the cursor in my input 
>field when the page loads, so that by doing this the page will scroll to 
>where my form is located.   So I've done this by using an onLoad function 
>that focuses the cursor in my form field, but I'm gettign an error that my 
>form field is not defined when the page loads.  This is caused, I believe, 
>because my onLoad code is located in an include that gets loaded into the 
>top of the page before the form (lower in the page) loads.
>
>How can I make the page wait to focus the cursor until my form is 
>loaded?  Thanks!!!
>
>- John
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>https://lists.LaTech.edu/mailman/listinfo/javascript





More information about the Javascript mailing list