Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004
    Kingston, Canada

    setting the focus

    Ok, this should be fairly simple. What I am trying to figure out is another way to do the following:

    <body onload="SetFocusOnLoad()">

    where SetFocusOnLoad() is a function that sets the focus (cursor) to a text box of a form.

    Now, my problem is that I am working on a part large website and the way things are set up is that the <body> tag is off somewhere in an 'include' and I don't have access to it. I'm just not familiar with JavaScript and PHP functions.

    So what I would like is another way to set the focus without needing access to the '<body> tag.

    I tried googling a bit, but I can't seem to come up with good search strings for this question.

    My site:

  2. #2
    I had a similar problem awhile ago, this code being the result.

    function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
    window.onload = func;
    } else {
    window.onload = function() {

    Just call that function anywhere, inline.

    <script type="text/javascript">

    It won't disturb any previous onload actions that you have in there.

  3. #3
    Join Date
    Jan 2003
    You could also consider a setTimeout() event, since IE likes to update form data after the actual load stage, which messes with any sense of state your scripts have. I love Micro$oft.
    Game Servers are the next hot market!
    Slim margins, heavy support, fickle customers, and moronic suppliers!
    Start your own today!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts