HTML setting focus on a form element on load
I'm looking for a way to set the focus on a text input box on an HTML form. The page is used for adding email addresses to our email list. When I have a stack of emails to add, it would be nice to not have to grab the mouse everytime the page reloads and click the text box. I didn't know if this could be done using HTML or if I need to turn to JS.
|
I think you should do something like:
Code:
<html> |
Cool, worked like a charm. I wish more sites would use this. There is one problem in my case. The body tag is in a separate document that is included in every page on our site. Is there any other event that I could use to trigger the function? I'm still learning JS and couldn't come up with anything else that's automatic. (Actually I am working on an online JS tutorial right now in another browser window;) It's working right now, but it's calling the function on every page on our site, which isn't a problem but I might like to modify it to focus different elements on different pages.
Thanks, |
just put the script at the end of your page, but out of the function, ie:
<script language...> document.formName.objectToFocus.focus(); </script> just put after you declare the object that needs the focus |
All times are GMT -5. The time now is 02:57 AM. |