[thelist] Direct focus on login
DUCROCQ Yann FT/DSI/SICOR
yann.ducrocq at francetelecom.com
Mon Nov 22 10:57:37 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>
>
Hi,
the variable "theForm" is useless in the function focusField.
The following code should work :
<html>
<head>
<script type="text/javascript">
window.onload=focusField;
function focusField() {
document.loginForm.userid.focus();
}
</script>
</head>
<body>
<form id="loginForm" name="loginForm">
<input type="text" name="userid" value="" />
</form>
</body>
</html>
Yanno
More information about the thelist
mailing list