anatak Posted December 10, 2007 Share Posted December 10, 2007 Hello, How can I put the focus to an input field when the page loads ? I would like the focus to go to the login form on my page. I tried tabindex="1" but that puts the focus only on the input field when the tab key is pressed. kind regards anatak Quote Link to comment https://forums.phpfreaks.com/topic/80937-solved-default-focus-to-an-input-field/ Share on other sites More sharing options...
phpQuestioner Posted December 10, 2007 Share Posted December 10, 2007 do it like this: <script language=""javascript> window.onload=function() { document.loginform.username.focus(); } </script> <form name="loginform" action="whatever.php" method="post"> Login: <input type="text" name="username"><br><br> Password: <input type="password" name="password"><br><br> <input type="submit" value="Sign In"> <input type="reset"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/80937-solved-default-focus-to-an-input-field/#findComment-410719 Share on other sites More sharing options...
anatak Posted December 10, 2007 Author Share Posted December 10, 2007 thank you I am going to put this on closed this may sound like a stupid question is there a way to do this if the user has javascript disabled ? My guess is no but I am not sure of course Quote Link to comment https://forums.phpfreaks.com/topic/80937-solved-default-focus-to-an-input-field/#findComment-410727 Share on other sites More sharing options...
phpQuestioner Posted December 10, 2007 Share Posted December 10, 2007 this may sound like a stupid question is there a way to do this if the user has javascript disabled ? not that I am aware of. Quote Link to comment https://forums.phpfreaks.com/topic/80937-solved-default-focus-to-an-input-field/#findComment-410779 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.