| Welcome to WebmasterWorld Guest from 18.104.22.168 |
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
|Become a Pro Member|
without using body onload
I'm trying to set focus on a form field but I'm using a cms where I can't edit the body tag or edit the head section.
Well, I can, but it's only on one page I want to use the code (the login page) and so I don't need the script on every page.
So here's the thing.
I've tried posting:
<!-- self.focus();document.login.username.focus() //--> </SCRIPT>
before and after the form (login) and it doesn't work.
Any tips on how to set the focus without changing the body tag or adding the JS to the head?
<form> ... </form>
Looks for an element with an id of "loginform"
Looks for <input> tags
Looks for the specified item. The first input tag is 0, the second is 1, etc
And then sets the focus..
But here's a problem - It seems to work initially when that form is loaded - But as the rest of the page loads, it looses focus.
Suggestions? Maybe I'll try placing the JS somewhere else..
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved