...

View Full Version : How to define the focus on page load?



turbo79
06-22-2010, 06:01 PM
Hi, I'm using ColdFusion to handle the login function for users (see login_form.cfm below). Have to click in the username box to be able to start typing. What's the best way to define the focus to be on the username when the page initially loads?

Thanks

<form method="post">
Username: <input type="Text" name="username"><br>
Password: <input type="Password" name="password"><br>
<input type="Submit" value="Login" name="login">
</form>

Philip M
06-22-2010, 06:10 PM
<body onload="document.formname.elementname.focus()">


Quizmaster: A peak in the Andes was confirmed by an expedition in 2000 to be the source of which river?
Contestant: The Nile.

abduraooft
06-22-2010, 06:10 PM
What's the best way to define the focus to be on the username when the page initially loads?


<script type="text/javascript">
window.onload=function(){
var elm=document.getElementById('username');
elm.focus();
}
</script>

<input type="Text" name="username" id="username">

turbo79
06-22-2010, 07:19 PM
Thanks Guys. Your tips and this page:
http://www.htmlcodetutorial.com/forms/index_famsupp_97.html

did the trick. Here's the working code in case anyone else is interested.

<body onload="document.forms.login.username.focus()">

<form name="login" method="post">
Username: <input type="Text" name="username"><br>
Password: <input type="Password" name="password"><br>
<input type="Submit" value="Login" name="login">
</form>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum