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 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> 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 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. 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
Archived
This topic is now archived and is closed to further replies.