dumdumsareyum Posted October 6, 2007 Share Posted October 6, 2007 I have a question that's probably really easy, but the only thing my javascript book has done for 8 chapters is teach me how to make every event create a popup window All I want to do is when the page opens have a certain form field already "in focus" and ready to be typed in so that the user does not have to click in it to start typing. I have some ideas about onload and focus and stuff, but i'm not really sure what to do. Thanks Quote Link to comment Share on other sites More sharing options...
emehrkay Posted October 6, 2007 Share Posted October 6, 2007 so you know how to add events when the page loads? if so, just do this document.getElementById('field').focus(); there you go. and you can be a little more complex for things like login forms. lets say you have a user field and password field, you can check the content of the userfield to see if it has any input, if not focus on it. if it does focus on the password field Quote Link to comment Share on other sites More sharing options...
dumdumsareyum Posted October 6, 2007 Author Share Posted October 6, 2007 ok, I added this: <body marginwidth="0" leftmargin="0" onLoad = document.getElementByID('password').focus() > but, no luck.......this part is called from an php include file, would that matter any? I also tried getElementsByName. Then I tried putting <script language="JavaScript"> <!-- document.getElementbyID('password').focus(); //--> </script> in the html right after the password field. Still no luck. What am I doing wrong? Quote Link to comment Share on other sites More sharing options...
Dragen Posted October 6, 2007 Share Posted October 6, 2007 wouldn't you need quotes around the onload? <body marginwidth="0" leftmargin="0" onLoad="document.getElementByID('password').focus()"> Quote Link to comment Share on other sites More sharing options...
mainewoods Posted October 6, 2007 Share Posted October 6, 2007 <body marginwidth="0" leftmargin="0" onLoad = "document.getElementByID('password').focus();"> --the 'd' in getElementById has to be a small d, you have a capital D Quote Link to comment Share on other sites More sharing options...
dumdumsareyum Posted October 7, 2007 Author Share Posted October 7, 2007 I put a lowercase D and added quotes around the onload, still nothing......I will try looking for some sample code and see Quote Link to comment Share on other sites More sharing options...
emehrkay Posted October 7, 2007 Share Posted October 7, 2007 <script type="text/javascript"> window.onload = function(){ document.getElementById('password').focus(); }; <script> thats all you need in your head Quote Link to comment Share on other sites More sharing options...
mainewoods Posted October 7, 2007 Share Posted October 7, 2007 document.getElementbyID('password').focus(); does your 'password' field actually have an id or just a name="password"? Give it an id too: <input type="password" name="password" id="password"> Quote Link to comment Share on other sites More sharing options...
dumdumsareyum Posted October 11, 2007 Author Share Posted October 11, 2007 Thanks a bunch! Worked like a charm, u guys are awesome Quote Link to comment 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.