[thelist] Direct focus on login

Sarah Sweeney mr.sanders at designshift.com
Mon Nov 22 11:17:43 CST 2004

>>I've found the following to work the most consistently in my 
>>own testing:
>>Include this script in the <head>:
>>function focusField(theForm, theField)
>>   theField.focus();
>>   theField.select();
>>And this in the body:
>><form id="loginForm" name="loginForm">
>>   <input type="text" name="userid" value="" />
>>   <script type="text/javascript">
>>   focusField(document.loginForm,document.loginForm.userid);
>>   </script>
>>   ...
> the variable "theForm" is useless in the function focusField.

Doh! Thanks for pointing that out.

> The following code should work :
> <html>
> <head>
> <script type="text/javascript">
> window.onload=focusField;
> <snip> 

I remember trying something like this when I first implemented this 
functionality and it didn't seem to work all of the time in the browsers 
I tested it in. I remember thinking it might have something to do with 
the window.onload firing before the entire form had loaded, but maybe 
I'm wrong.

Sarah Sweeney  ::  Web Developer & Programmer
Portfolio  ::  http://sarah.designshift.com
Blog  ::  http://hardedge.ca

More information about the thelist mailing list