[thelist] Direct focus on login
Sarah Sweeney
mr.sanders at designshift.com
Mon Nov 22 10:27:07 CST 2004
On 11/22/2004 10:53 AM Andreas Wahlin wrote:
> I want to place the cursor on the userid area of a loginscreen, so
> user's won't have to click on it. Should be easy javascript:
>
> <body onload="document.getElementById("userid").focus();">
> <input type="text" id="userid" name="userid" />
> </body>
>
> However, the cursor won't start to blink/being active unltil I click
> once on the actual page, (though that click can be anywhere). This
> defeats the entire purpouse. It's like, sure the input is focused, but
> the window isn't focused, but it is. I have tried refreshing the window
> and I've tried opening a fresh window and paste the url and then go
> there, and nothing makes it so I can start typing directly without first
> clicking somewhere on the window.
> (hope this hasn't been asked before, I did some googling)
>
> Andreas
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>
...
</form>
--
Sarah Sweeney :: Web Developer & Programmer
Portfolio :: http://sarah.designshift.com
Blog :: http://hardedge.ca
More information about the thelist
mailing list