onLoad setting focus to a button or a link?...

Posted on 2003-03-23
Medium Priority
Last Modified: 2006-11-17
I'm helping to build a data entry intensive application.  On a confirmation page the user will receive textual confirmation that the data they entered on the previous form has been submitted.  Underneath that are four options to choose from to continue in the data entry process (list, new, copy, edit).  When this page is loaded to have focus set on the first button or hyperlink (either way is fine) when the page loads.  Sometimes when the page loads and I hit 'Tab' it will drop me on the first link, but sometimes it doesn't and it's rather inconsistent.  I tried using the standard:

<body onload="document.form_name.input_name.focus()">

but it returns a javascript error even if I set the item as an image field in a form.  Is there an easy way to set focus on a button or hyperlink upon load?  The onLoad event of course works with a text field, but I haven't gotten it or similar to work with a button or hyperlink.  It doesn't even need to actually select the item.  It would be more than acceptable if the user was able to hit 'Tab' once and be on the first selection.  I need this to work in IE 4-6, Netscape 4-7.  Any suggestions?
Question by:swankboy
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 46

Accepted Solution

fritz_the_blank earned 200 total points
ID: 8190736


Fritz the Blank

Expert Comment

ID: 8192712
Hi there.
You can't control pageelement on the "onload" event. Simply because the HTML parser reads the content from top down. Meening that if you put any elements in the onload the only element loaded at that time is the body!.

Instead you could try putting somthing like this at the bottom of your html file.
bla bla bla bla bla a kjh asdfnbdas
asdfh aksfhd kasjhdf
askhdfkajs hdf


Best regards from Denmark
LVL 46

Expert Comment

ID: 8195096
I am not sure that is true. My understanding is that onLoad() executes as soon as the page is finished loading.

Fritz the Blank

Author Comment

ID: 8196376
This worked perfectly.  xaungxaj gave me pretty much the same thing so I just accepted this one as it was first.  Also the onLoad event doesn't trigger until the page is completely loaded.  That's why when you go to start filling out a form and the page loads and all of a sudden you're typing in the wrong box because the event triggered the focus and you started typing before the page fully loaded.  Very annoying.  Thanks!  I wish I didn't have to use form images, but it works. Thanks!
LVL 46

Expert Comment

ID: 8196397
Glad to have helped,

Fritz the Blank

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question