dmccabe Posted August 15, 2008 Share Posted August 15, 2008 I have a simple form (two text boxes and a submit button) and I want it so when he page loads the cursor is already in the first of the 2 text boxes, can anyone point me in the right direction <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="login"> <div id="login_top"> <div id="login_box"> <input type="text" name="ldapname" size="30"><br /><br /> <input type="password" name="ldappass" size="30"> </div> </div> <div id="login_bottom"> <div id="login_btn"> <input type="submit" value="Login" name="submit"> <input type="submit" value="Cancel" name="submit"> </div> </div> </div> </form> Link to comment https://forums.phpfreaks.com/topic/119801-setting-focus-to-a-form-text-box/ Share on other sites More sharing options...
ratcateme Posted August 15, 2008 Share Posted August 15, 2008 javascript focus() and <body onload=""> Scott. Link to comment https://forums.phpfreaks.com/topic/119801-setting-focus-to-a-form-text-box/#findComment-617188 Share on other sites More sharing options...
dmccabe Posted August 15, 2008 Author Share Posted August 15, 2008 Sorry Scott I am bit of a n00b and dont exactly know what you mean, can you expand on it a little please. Link to comment https://forums.phpfreaks.com/topic/119801-setting-focus-to-a-form-text-box/#findComment-617200 Share on other sites More sharing options...
ratcateme Posted August 15, 2008 Share Posted August 15, 2008 add this onto your <body> tag <body onload="document.getElementById(\"text_area_id\").focus()"> that should do it. Scott. Link to comment https://forums.phpfreaks.com/topic/119801-setting-focus-to-a-form-text-box/#findComment-617201 Share on other sites More sharing options...
dmccabe Posted August 15, 2008 Author Share Posted August 15, 2008 Thanks again for the fast reply. Doesnt seem to be working though. I have it like this at the moment: <body onload="document.getElementById(\"text_area_id\").focus()"> <div id="login"> <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="login" id="ldapname"> <div id="login_top"> <div id="login_box"> <input type="text" name="ldapname" size="30"><br /><br /> <input type="password" name="ldappass" size="30"> </div> </div> <div id="login_bottom"> <div id="login_btn"> <input type="submit" value="Login" name="submit"> <input type="submit" value="Cancel" name="submit"> </div> </div> </div> </form> however I also tried changing the "text_area_id" part to "ldapname" and it didnt work there either. Any ideas? Link to comment https://forums.phpfreaks.com/topic/119801-setting-focus-to-a-form-text-box/#findComment-617274 Share on other sites More sharing options...
JasonLewis Posted August 15, 2008 Share Posted August 15, 2008 You need an id attribute. id and name are different, get into the habit of setting an id to inputs. Remember, it must be unique. <input type="text" name="ldapname" id="ldapname" size="30"> Link to comment https://forums.phpfreaks.com/topic/119801-setting-focus-to-a-form-text-box/#findComment-617369 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.